Spaces:
Sleeping
Sleeping
Update app.py
Browse filesReasoning output
app.py
CHANGED
|
@@ -12,12 +12,13 @@ import json
|
|
| 12 |
from PIL import Image
|
| 13 |
from io import BytesIO
|
| 14 |
import math
|
|
|
|
| 15 |
import requests
|
| 16 |
from urllib.parse import quote
|
| 17 |
from multiprocessing import context
|
| 18 |
# from agents.tool import WebSearchTool
|
| 19 |
from typing_extensions import TypedDict, Any
|
| 20 |
-
from agents import Agent, FunctionTool, ImageGenerationTool, RunContextWrapper, Runner, function_tool, CodeInterpreterTool
|
| 21 |
from openai import OpenAI
|
| 22 |
from markdown_pdf import MarkdownPdf
|
| 23 |
from markdown_pdf import Section
|
|
@@ -270,6 +271,7 @@ async def chat(prompt_window, user_window, password, history, output_window,
|
|
| 270 |
|
| 271 |
agent = Agent(name="Assistant",
|
| 272 |
instructions=instructions,
|
|
|
|
| 273 |
tools=[get_distance, search_web, get_news,
|
| 274 |
CodeInterpreterTool(tool_config={"type": "code_interpreter","container": code_container}), # make_pdf,
|
| 275 |
ImageGenerationTool(tool_config={"type": "image_generation", "quality": "low"},)],)
|
|
@@ -341,6 +343,7 @@ async def chat(prompt_window, user_window, password, history, output_window,
|
|
| 341 |
inputs.append({"role":"user", "content":prompt})
|
| 342 |
exception_msg = ''
|
| 343 |
result = None
|
|
|
|
| 344 |
try:
|
| 345 |
result = await Runner.run(agent, max_turns=20,
|
| 346 |
input=inputs)
|
|
@@ -355,8 +358,14 @@ async def chat(prompt_window, user_window, password, history, output_window,
|
|
| 355 |
fp.write(base64.b64decode(img_result))
|
| 356 |
image_window = gr.Image(visible=True, value=image_out_path)
|
| 357 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 358 |
reply = md(result.final_output)
|
| 359 |
response += "\n\n***YOU***: " + prompt + "\n\n***GPT***: " + reply.replace('```','\n\n```\n\n')
|
|
|
|
|
|
|
| 360 |
history.append({"role":"assistant", "content":result.final_output})
|
| 361 |
except Exception as e:
|
| 362 |
exception_msg = f'Error: {e.message}'
|
|
|
|
| 12 |
from PIL import Image
|
| 13 |
from io import BytesIO
|
| 14 |
import math
|
| 15 |
+
from openai.types import Reasoning
|
| 16 |
import requests
|
| 17 |
from urllib.parse import quote
|
| 18 |
from multiprocessing import context
|
| 19 |
# from agents.tool import WebSearchTool
|
| 20 |
from typing_extensions import TypedDict, Any
|
| 21 |
+
from agents import Agent, FunctionTool, ImageGenerationTool, RunContextWrapper, Runner, function_tool, CodeInterpreterTool, ModelSettings
|
| 22 |
from openai import OpenAI
|
| 23 |
from markdown_pdf import MarkdownPdf
|
| 24 |
from markdown_pdf import Section
|
|
|
|
| 271 |
|
| 272 |
agent = Agent(name="Assistant",
|
| 273 |
instructions=instructions,
|
| 274 |
+
model_settings=ModelSettings(reasoning=Reasoning(effort='low', summary='detailed')),
|
| 275 |
tools=[get_distance, search_web, get_news,
|
| 276 |
CodeInterpreterTool(tool_config={"type": "code_interpreter","container": code_container}), # make_pdf,
|
| 277 |
ImageGenerationTool(tool_config={"type": "image_generation", "quality": "low"},)],)
|
|
|
|
| 343 |
inputs.append({"role":"user", "content":prompt})
|
| 344 |
exception_msg = ''
|
| 345 |
result = None
|
| 346 |
+
reasoning = ''
|
| 347 |
try:
|
| 348 |
result = await Runner.run(agent, max_turns=20,
|
| 349 |
input=inputs)
|
|
|
|
| 358 |
fp.write(base64.b64decode(img_result))
|
| 359 |
image_window = gr.Image(visible=True, value=image_out_path)
|
| 360 |
|
| 361 |
+
for item in result.raw_responses[0].output:
|
| 362 |
+
if item.type == 'reasoning' and item.summary:
|
| 363 |
+
reasoning += item.summary[0].text
|
| 364 |
+
|
| 365 |
reply = md(result.final_output)
|
| 366 |
response += "\n\n***YOU***: " + prompt + "\n\n***GPT***: " + reply.replace('```','\n\n```\n\n')
|
| 367 |
+
if reasoning != '':
|
| 368 |
+
response += '\n\n**Reasoning:**\n' + reasoning + '\n'
|
| 369 |
history.append({"role":"assistant", "content":result.final_output})
|
| 370 |
except Exception as e:
|
| 371 |
exception_msg = f'Error: {e.message}'
|