Spaces:
Sleeping
Sleeping
Create app/agent/agent.py
Browse files- app/agent/agent.py +40 -0
app/agent/agent.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import json
|
| 3 |
+
from config import Config
|
| 4 |
+
import tools
|
| 5 |
+
|
| 6 |
+
class Agent:
|
| 7 |
+
|
| 8 |
+
def __init__(self):
|
| 9 |
+
self.history = []
|
| 10 |
+
|
| 11 |
+
def call_llm(self, messages):
|
| 12 |
+
res = requests.post(
|
| 13 |
+
Config.LLM_API_URL,
|
| 14 |
+
headers={
|
| 15 |
+
"Authorization": f"Bearer {Config.LLM_API_KEY}",
|
| 16 |
+
"Content-Type": "application/json"
|
| 17 |
+
},
|
| 18 |
+
json={
|
| 19 |
+
"model": Config.MODEL,
|
| 20 |
+
"messages": messages,
|
| 21 |
+
"temperature": 0.2
|
| 22 |
+
}
|
| 23 |
+
)
|
| 24 |
+
return res.json()
|
| 25 |
+
|
| 26 |
+
def run(self, user_input):
|
| 27 |
+
|
| 28 |
+
messages = [
|
| 29 |
+
{"role": "system", "content": Config.SYSTEM_PROMPT},
|
| 30 |
+
{"role": "user", "content": user_input}
|
| 31 |
+
]
|
| 32 |
+
|
| 33 |
+
response = self.call_llm(messages)
|
| 34 |
+
|
| 35 |
+
return response
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
if __name__ == "__main__":
|
| 39 |
+
agent = Agent()
|
| 40 |
+
print(agent.run("Explain this project structure"))
|