Commit
·
08d3fd4
1
Parent(s):
0d1ac3e
change to openai
Browse files
app.py
CHANGED
|
@@ -18,6 +18,34 @@ import yaml
|
|
| 18 |
#with open("prompts.yaml", 'r') as stream:
|
| 19 |
# prompt_templates = yaml.safe_load(stream)
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
MyAgent = CodeAgent(
|
| 22 |
model= InferenceClientModel(model_id="Qwen/Qwen2.5-Coder-32B-Instruct"),
|
| 23 |
tools=[],
|
|
@@ -70,7 +98,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 70 |
|
| 71 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
| 72 |
try:
|
| 73 |
-
agent =
|
| 74 |
except Exception as e:
|
| 75 |
print(f"Error instantiating agent: {e}")
|
| 76 |
return f"Error initializing agent: {e}", None
|
|
|
|
| 18 |
#with open("prompts.yaml", 'r') as stream:
|
| 19 |
# prompt_templates = yaml.safe_load(stream)
|
| 20 |
|
| 21 |
+
import os
|
| 22 |
+
from dotenv import load_dotenv
|
| 23 |
+
|
| 24 |
+
# 1) load your .env (skip if you set it in the shell)
|
| 25 |
+
load_dotenv()
|
| 26 |
+
|
| 27 |
+
# 2) grab the key
|
| 28 |
+
openai_api_key = os.getenv("OPENAI_API_KEY")
|
| 29 |
+
|
| 30 |
+
# 3) build the Smolagents model
|
| 31 |
+
from smolagents import OpenAIServerModel
|
| 32 |
+
|
| 33 |
+
model = OpenAIServerModel(
|
| 34 |
+
model_id="gpt-4.1", # or "gpt-3.5-turbo", etc.
|
| 35 |
+
api_base="https://api.openai.com/v1", # OpenAI’s standard endpoint
|
| 36 |
+
api_key=openai_api_key # your secret key
|
| 37 |
+
) # :contentReference[oaicite:1]{index=1}
|
| 38 |
+
|
| 39 |
+
# 4) create a CodeAgent powered by that model
|
| 40 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool
|
| 41 |
+
|
| 42 |
+
OpenAIAgent = CodeAgent(
|
| 43 |
+
tools=[DuckDuckGoSearchTool()], # any tools you want
|
| 44 |
+
model=model,
|
| 45 |
+
# you can allow extra imports if needed:
|
| 46 |
+
# additional_authorized_imports=["requests", "bs4"],
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
MyAgent = CodeAgent(
|
| 50 |
model= InferenceClientModel(model_id="Qwen/Qwen2.5-Coder-32B-Instruct"),
|
| 51 |
tools=[],
|
|
|
|
| 98 |
|
| 99 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
| 100 |
try:
|
| 101 |
+
agent = OpenAIAgent()
|
| 102 |
except Exception as e:
|
| 103 |
print(f"Error instantiating agent: {e}")
|
| 104 |
return f"Error initializing agent: {e}", None
|