mobinln commited on
Commit
b6e4778
·
verified ·
1 Parent(s): 7dcd888

V 1.1 (Agno)

Browse files
Files changed (1) hide show
  1. app.py +13 -91
app.py CHANGED
@@ -2,10 +2,19 @@ import subprocess
2
  import gradio as gr
3
  from openai import OpenAI
4
  import json
 
 
5
 
6
  subprocess.Popen("bash /home/user/app/start.sh", shell=True)
7
 
8
- client = OpenAI(base_url="http://0.0.0.0:8000/v1", api_key="sk-local", timeout=600)
 
 
 
 
 
 
 
9
 
10
  def handle_function_call(function_name, arguments):
11
  """Handle function calls from the model"""
@@ -30,8 +39,6 @@ def respond(
30
  message,
31
  history: list[tuple[str, str]] = [],
32
  system_message=None,
33
- max_tokens=None,
34
- temperature=0.7,
35
  ):
36
  messages = []
37
  if system_message:
@@ -46,97 +53,12 @@ def respond(
46
  messages.append({"role": "user", "content": message})
47
 
48
  try:
49
- stream = client.chat.completions.create(
50
- model="Deepseek-R1-0528-Qwen3-8B",
51
- messages=messages,
52
- max_tokens=max_tokens,
53
- temperature=temperature,
54
- stream=True,
55
- tools=[
56
- {
57
- "type": "function",
58
- "function": {
59
- "name": "browser_search",
60
- "description": (
61
- "Search the web for a given query and return the most relevant results."
62
- ),
63
- "parameters": {
64
- "type": "object",
65
- "properties": {
66
- "query": {
67
- "type": "string",
68
- "description": "The search query string.",
69
- },
70
- "max_results": {
71
- "type": "integer",
72
- "description": (
73
- "Maximum number of search results to return. "
74
- "If omitted the service will use its default."
75
- ),
76
- "default": 5,
77
- },
78
- },
79
- "required": ["query"],
80
- },
81
- },
82
- },
83
- {
84
- "type": "function",
85
- "function": {
86
- "name": "code_interpreter",
87
- "description": (
88
- "Execute Python code and return the results. "
89
- "Can generate plots, perform calculations, and data analysis."
90
- ),
91
- "parameters": {
92
- "type": "object",
93
- "properties": {
94
- "code": {
95
- "type": "string",
96
- "description": "The Python code to execute.",
97
- },
98
- },
99
- "required": ["code"],
100
- },
101
- },
102
- },
103
- ],
104
- )
105
-
106
  print("messages", messages)
107
- output = ""
108
- reasoning = ""
109
- function_calls_to_handle = []
110
 
111
  for chunk in stream:
112
- delta = chunk.choices[0].delta
113
-
114
- if hasattr(delta, "tool_calls") and delta.tool_calls:
115
- for tool_call in delta.tool_calls:
116
- if tool_call.function:
117
- function_calls_to_handle.append(
118
- {
119
- "name": tool_call.function.name,
120
- "arguments": json.loads(tool_call.function.arguments),
121
- }
122
- )
123
-
124
- if hasattr(delta, "reasoning_content") and delta.reasoning_content:
125
- reasoning += delta.reasoning_content
126
- elif delta.content:
127
- output += delta.content
128
-
129
- yield f"*{reasoning}*\n{output}"
130
-
131
- if function_calls_to_handle:
132
- for func_call in function_calls_to_handle:
133
- func_result = handle_function_call(
134
- func_call["name"], func_call["arguments"]
135
- )
136
- output += (
137
- f"\n\n**Function Result ({func_call['name']}):**\n{func_result}"
138
- )
139
- yield output
140
 
141
  except Exception as e:
142
  print(f"[Error] {e}")
 
2
  import gradio as gr
3
  from openai import OpenAI
4
  import json
5
+ from agno.agent import Agent, RunResponse
6
+ from agno.models.openai.like import OpenAILike
7
 
8
  subprocess.Popen("bash /home/user/app/start.sh", shell=True)
9
 
10
+ agent = Agent(
11
+ model=OpenAILike(
12
+ id="model",
13
+ api_key="no-token",
14
+ base_url="http://0.0.0.0:8000/v1",
15
+ )
16
+ )
17
+
18
 
19
  def handle_function_call(function_name, arguments):
20
  """Handle function calls from the model"""
 
39
  message,
40
  history: list[tuple[str, str]] = [],
41
  system_message=None,
 
 
42
  ):
43
  messages = []
44
  if system_message:
 
53
  messages.append({"role": "user", "content": message})
54
 
55
  try:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  print("messages", messages)
57
+ stream = agent.run(messages=messages, stream=True)
 
 
58
 
59
  for chunk in stream:
60
+ print("chunk", chunk)
61
+ yield chunk.choices[0].delta.content
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
 
63
  except Exception as e:
64
  print(f"[Error] {e}")