Spaces:
Runtime error
Runtime error
Commit ·
bdc85fb
1
Parent(s): b3c478b
ernamed main and got app.py for git repo query
Browse files- app.py +90 -53
- main.py +0 -101
- old-app.py +64 -0
app.py
CHANGED
|
@@ -1,64 +1,101 @@
|
|
| 1 |
-
import
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
def
|
| 11 |
-
message,
|
| 12 |
-
history: list[tuple[str, str]],
|
| 13 |
-
system_message,
|
| 14 |
-
max_tokens,
|
| 15 |
-
temperature,
|
| 16 |
-
top_p,
|
| 17 |
-
):
|
| 18 |
-
messages = [{"role": "system", "content": system_message}]
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
)
|
| 61 |
-
|
| 62 |
|
| 63 |
if __name__ == "__main__":
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import asyncio
|
| 2 |
+
import os
|
| 3 |
+
from agents import (
|
| 4 |
+
Agent,
|
| 5 |
+
OpenAIChatCompletionsModel,
|
| 6 |
+
Runner,
|
| 7 |
+
set_tracing_disabled,
|
| 8 |
+
)
|
| 9 |
+
from agents.mcp import MCPServer, MCPServerStdio
|
| 10 |
+
from openai import AsyncOpenAI
|
| 11 |
+
from dotenv import load_dotenv
|
| 12 |
+
load_dotenv()
|
| 13 |
|
| 14 |
+
api_key = os.environ["NEBIUS_API_KEY"]
|
| 15 |
+
base_url = "https://api.studio.nebius.ai/v1"
|
| 16 |
+
client = AsyncOpenAI(base_url=base_url, api_key=api_key)
|
| 17 |
+
set_tracing_disabled(disabled=True)
|
| 18 |
|
| 19 |
+
async def run(mcp_server: MCPServer, repo_url: str):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
+
parts = repo_url.strip("/").split("/")
|
| 22 |
+
owner = parts[-2] if len(parts) >= 2 else None
|
| 23 |
+
repo = parts[-1] if len(parts) >= 1 else None
|
| 24 |
+
|
| 25 |
+
if not owner or not repo:
|
| 26 |
+
print("Invalid repository URL. Please provide URL in format: owner/repo")
|
| 27 |
+
return
|
| 28 |
|
| 29 |
+
agent = Agent(
|
| 30 |
+
name="GitHub Assistant",
|
| 31 |
+
instructions=f"""You are a GitHub repository analyzer for {repo_url}.
|
| 32 |
+
Focus on providing detailed analysis of repository issues and commits.
|
| 33 |
+
For issues, use list_issues with sort='created' and direction='desc' to get the latest issues.
|
| 34 |
+
For commits, use list_commits to get the latest commits.
|
| 35 |
+
When using numeric parameters like per_page, do not include quotes as they should be numbers, not strings.
|
| 36 |
+
Provide detailed explanations of the findings.""",
|
| 37 |
+
mcp_servers=[mcp_server],
|
| 38 |
+
model=OpenAIChatCompletionsModel(
|
| 39 |
+
model="meta-llama/Meta-Llama-3.1-8B-Instruct",
|
| 40 |
+
openai_client=client
|
| 41 |
+
)
|
| 42 |
+
)
|
| 43 |
|
| 44 |
+
async def run_query(message):
|
| 45 |
+
print("\n" + "-" * 40)
|
| 46 |
+
print(f"Running: {message}")
|
| 47 |
+
result = await Runner.run(starting_agent=agent, input=message)
|
| 48 |
+
print(result.final_output)
|
| 49 |
|
| 50 |
+
# Updated queries with correct parameter types
|
| 51 |
+
queries = [
|
| 52 |
+
f"""Using list_issues tool, find and analyze the most recent issue in the repository.
|
| 53 |
+
Parameters to use:
|
| 54 |
+
- owner: {owner}
|
| 55 |
+
- repo: {repo}
|
| 56 |
+
- state: 'all'
|
| 57 |
+
- sort: 'created'
|
| 58 |
+
- direction: 'desc'
|
| 59 |
+
- per_page: 1 # Note: This is a number, not a string""",
|
| 60 |
+
|
| 61 |
+
f"""Using list_commits tool, analyze the most recent commit to the repository.
|
| 62 |
+
Parameters to use:
|
| 63 |
+
- owner: {owner}
|
| 64 |
+
- repo: {repo}
|
| 65 |
+
- per_page: 1 # Note: This is a number, not a string"""
|
| 66 |
+
]
|
| 67 |
|
| 68 |
+
for query in queries:
|
| 69 |
+
await run_query(query)
|
| 70 |
|
| 71 |
+
async def main():
|
| 72 |
+
print("GitHub Repository Analysis Tool")
|
| 73 |
+
print("-" * 30)
|
| 74 |
+
repo_url = input("Enter GitHub repository URL (format: owner/repo): ")
|
| 75 |
|
| 76 |
+
async with MCPServerStdio(
|
| 77 |
+
cache_tools_list=True,
|
| 78 |
+
params={
|
| 79 |
+
"command": "npx",
|
| 80 |
+
"args": [
|
| 81 |
+
"-y",
|
| 82 |
+
"@modelcontextprotocol/server-github"
|
| 83 |
+
],
|
| 84 |
+
"env": {
|
| 85 |
+
"GITHUB_PERSONAL_ACCESS_TOKEN": os.environ["GITHUB_PERSONAL_ACCESS_TOKEN"],
|
| 86 |
+
}
|
| 87 |
+
},
|
| 88 |
+
) as server:
|
| 89 |
+
try:
|
| 90 |
+
await run(server, repo_url)
|
| 91 |
+
except Exception as e:
|
| 92 |
+
print(f"Error analyzing repository: {e}")
|
|
|
|
|
|
|
| 93 |
|
| 94 |
if __name__ == "__main__":
|
| 95 |
+
|
| 96 |
+
load_dotenv()
|
| 97 |
+
if not os.getenv("GITHUB_PERSONAL_ACCESS_TOKEN"):
|
| 98 |
+
raise RuntimeError("GITHUB_PERSONAL_ACCESS_TOKEN not found in environment variables")
|
| 99 |
+
|
| 100 |
+
set_tracing_disabled(disabled=True)
|
| 101 |
+
asyncio.run(main())
|
main.py
DELETED
|
@@ -1,101 +0,0 @@
|
|
| 1 |
-
import asyncio
|
| 2 |
-
import os
|
| 3 |
-
from agents import (
|
| 4 |
-
Agent,
|
| 5 |
-
OpenAIChatCompletionsModel,
|
| 6 |
-
Runner,
|
| 7 |
-
set_tracing_disabled,
|
| 8 |
-
)
|
| 9 |
-
from agents.mcp import MCPServer, MCPServerStdio
|
| 10 |
-
from openai import AsyncOpenAI
|
| 11 |
-
from dotenv import load_dotenv
|
| 12 |
-
load_dotenv()
|
| 13 |
-
|
| 14 |
-
api_key = os.environ["NEBIUS_API_KEY"]
|
| 15 |
-
base_url = "https://api.studio.nebius.ai/v1"
|
| 16 |
-
client = AsyncOpenAI(base_url=base_url, api_key=api_key)
|
| 17 |
-
set_tracing_disabled(disabled=True)
|
| 18 |
-
|
| 19 |
-
async def run(mcp_server: MCPServer, repo_url: str):
|
| 20 |
-
|
| 21 |
-
parts = repo_url.strip("/").split("/")
|
| 22 |
-
owner = parts[-2] if len(parts) >= 2 else None
|
| 23 |
-
repo = parts[-1] if len(parts) >= 1 else None
|
| 24 |
-
|
| 25 |
-
if not owner or not repo:
|
| 26 |
-
print("Invalid repository URL. Please provide URL in format: owner/repo")
|
| 27 |
-
return
|
| 28 |
-
|
| 29 |
-
agent = Agent(
|
| 30 |
-
name="GitHub Assistant",
|
| 31 |
-
instructions=f"""You are a GitHub repository analyzer for {repo_url}.
|
| 32 |
-
Focus on providing detailed analysis of repository issues and commits.
|
| 33 |
-
For issues, use list_issues with sort='created' and direction='desc' to get the latest issues.
|
| 34 |
-
For commits, use list_commits to get the latest commits.
|
| 35 |
-
When using numeric parameters like per_page, do not include quotes as they should be numbers, not strings.
|
| 36 |
-
Provide detailed explanations of the findings.""",
|
| 37 |
-
mcp_servers=[mcp_server],
|
| 38 |
-
model=OpenAIChatCompletionsModel(
|
| 39 |
-
model="meta-llama/Meta-Llama-3.1-8B-Instruct",
|
| 40 |
-
openai_client=client
|
| 41 |
-
)
|
| 42 |
-
)
|
| 43 |
-
|
| 44 |
-
async def run_query(message):
|
| 45 |
-
print("\n" + "-" * 40)
|
| 46 |
-
print(f"Running: {message}")
|
| 47 |
-
result = await Runner.run(starting_agent=agent, input=message)
|
| 48 |
-
print(result.final_output)
|
| 49 |
-
|
| 50 |
-
# Updated queries with correct parameter types
|
| 51 |
-
queries = [
|
| 52 |
-
f"""Using list_issues tool, find and analyze the most recent issue in the repository.
|
| 53 |
-
Parameters to use:
|
| 54 |
-
- owner: {owner}
|
| 55 |
-
- repo: {repo}
|
| 56 |
-
- state: 'all'
|
| 57 |
-
- sort: 'created'
|
| 58 |
-
- direction: 'desc'
|
| 59 |
-
- per_page: 1 # Note: This is a number, not a string""",
|
| 60 |
-
|
| 61 |
-
f"""Using list_commits tool, analyze the most recent commit to the repository.
|
| 62 |
-
Parameters to use:
|
| 63 |
-
- owner: {owner}
|
| 64 |
-
- repo: {repo}
|
| 65 |
-
- per_page: 1 # Note: This is a number, not a string"""
|
| 66 |
-
]
|
| 67 |
-
|
| 68 |
-
for query in queries:
|
| 69 |
-
await run_query(query)
|
| 70 |
-
|
| 71 |
-
async def main():
|
| 72 |
-
print("GitHub Repository Analysis Tool")
|
| 73 |
-
print("-" * 30)
|
| 74 |
-
repo_url = input("Enter GitHub repository URL (format: owner/repo): ")
|
| 75 |
-
|
| 76 |
-
async with MCPServerStdio(
|
| 77 |
-
cache_tools_list=True,
|
| 78 |
-
params={
|
| 79 |
-
"command": "npx",
|
| 80 |
-
"args": [
|
| 81 |
-
"-y",
|
| 82 |
-
"@modelcontextprotocol/server-github"
|
| 83 |
-
],
|
| 84 |
-
"env": {
|
| 85 |
-
"GITHUB_PERSONAL_ACCESS_TOKEN": os.environ["GITHUB_PERSONAL_ACCESS_TOKEN"],
|
| 86 |
-
}
|
| 87 |
-
},
|
| 88 |
-
) as server:
|
| 89 |
-
try:
|
| 90 |
-
await run(server, repo_url)
|
| 91 |
-
except Exception as e:
|
| 92 |
-
print(f"Error analyzing repository: {e}")
|
| 93 |
-
|
| 94 |
-
if __name__ == "__main__":
|
| 95 |
-
|
| 96 |
-
load_dotenv()
|
| 97 |
-
if not os.getenv("GITHUB_PERSONAL_ACCESS_TOKEN"):
|
| 98 |
-
raise RuntimeError("GITHUB_PERSONAL_ACCESS_TOKEN not found in environment variables")
|
| 99 |
-
|
| 100 |
-
set_tracing_disabled(disabled=True)
|
| 101 |
-
asyncio.run(main())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
old-app.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from huggingface_hub import InferenceClient
|
| 3 |
+
|
| 4 |
+
"""
|
| 5 |
+
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
| 6 |
+
"""
|
| 7 |
+
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def respond(
|
| 11 |
+
message,
|
| 12 |
+
history: list[tuple[str, str]],
|
| 13 |
+
system_message,
|
| 14 |
+
max_tokens,
|
| 15 |
+
temperature,
|
| 16 |
+
top_p,
|
| 17 |
+
):
|
| 18 |
+
messages = [{"role": "system", "content": system_message}]
|
| 19 |
+
|
| 20 |
+
for val in history:
|
| 21 |
+
if val[0]:
|
| 22 |
+
messages.append({"role": "user", "content": val[0]})
|
| 23 |
+
if val[1]:
|
| 24 |
+
messages.append({"role": "assistant", "content": val[1]})
|
| 25 |
+
|
| 26 |
+
messages.append({"role": "user", "content": message})
|
| 27 |
+
|
| 28 |
+
response = ""
|
| 29 |
+
|
| 30 |
+
for message in client.chat_completion(
|
| 31 |
+
messages,
|
| 32 |
+
max_tokens=max_tokens,
|
| 33 |
+
stream=True,
|
| 34 |
+
temperature=temperature,
|
| 35 |
+
top_p=top_p,
|
| 36 |
+
):
|
| 37 |
+
token = message.choices[0].delta.content
|
| 38 |
+
|
| 39 |
+
response += token
|
| 40 |
+
yield response
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
"""
|
| 44 |
+
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
| 45 |
+
"""
|
| 46 |
+
demo = gr.ChatInterface(
|
| 47 |
+
respond,
|
| 48 |
+
additional_inputs=[
|
| 49 |
+
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
| 50 |
+
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 51 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 52 |
+
gr.Slider(
|
| 53 |
+
minimum=0.1,
|
| 54 |
+
maximum=1.0,
|
| 55 |
+
value=0.95,
|
| 56 |
+
step=0.05,
|
| 57 |
+
label="Top-p (nucleus sampling)",
|
| 58 |
+
),
|
| 59 |
+
],
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
if __name__ == "__main__":
|
| 64 |
+
demo.launch()
|