Spaces:
Sleeping
Sleeping
tjrtm commited on
Commit ·
78a3ab9
1
Parent(s): d579ced
web search and coding tools added
Browse files9 unmodified lines10111213141516171819204 unmodified lines2526272829303132333435363738394041424344454647489 unmodified linesprint("BasicAgent initialized.")def __call__(self, question: str, image: Optional["PIL.Image.Image"] = None) -> str:print(f"Agent received question (first 50 chars): {question[:50]}...")system_prompt = ("I'm a reasoning-based chatbot. Ask me anything! I always use <think> and add my reasoning in <think> tags. ""You can also upload an image, and I will analyze it and provide reasoning about its content using <think> tags.")# Handle Gradio's possible list wrappingif isinstance(image, list):image = image[0] if image else Noneif image is not None:from io import BytesIOfrom PIL import Image4 unmodified linesimage_bytes = buffered.getvalue()image_b64 = base64.b64encode(image_bytes).decode("utf-8")image_url = f"data:image/png;base64,{image_b64}"messages = [{"role": "system", "content": system_prompt},{"role": "user", "content": [{"type": "text", "text": question},{"type": "image_url", "image_url": {"url": image_url}}]}]else:messages = [{"role": "system", "content": system_prompt},{"role": "user", "content": question}]response = openai.chat.completions.create(model="gpt-4.1-nano",messages=messages)answer = response.choices[0].message.contentreturn answeragent = BasicAgent()9 unmodified lines1011121314151617181920212223244 unmodified lines29303132333435363738394041424344454647484950515253545556579 unmodified linesprint("BasicAgent initialized.")def __call__(self, question: str, image: Optional["PIL.Image.Image"] = None) -> str:print(f"Agent received question (first 50 chars): {question[:50]}...")system_prompt = ("You are a reasoning-based chatbot. Ask me anything! I always use <think> and add my reasoning in <think> tags. ""You can also upload an image, and I will analyze it and provide reasoning about its content using <think> tags. ""You have access to web search and other tools to provide up-to-date and accurate answers, always citing your sources when using external information.")# Handle Gradio's possible list wrappingif isinstance(image, list):image = image[0] if image else Nonemessages = [{"role": "system", "content": system_prompt}]if image is not None:from io import BytesIOfrom PIL import Image4 unmodified linesimage_bytes = buffered.getvalue()image_b64 = base64.b64encode(image_bytes).decode("utf-8")image_url = f"data:image/png;base64,{image_b64}"messages.append({"role": "user","content": [{"type": "text", "text": question},{"type": "image_url", "image_url": {"url": image_url}}]})else:messages.append({"role": "user", "content": question})response = openai.responses.create(model="gpt-4o",tools=[{"type": "web_search_preview"},{"type": "code_interpreter"}],input=messages)# The responses API returns output_text for the main answeranswer = getattr(response, "output_text", None)if not answer and hasattr(response, "output") and response.output:# fallback for older/newer SDKsanswer = response.output[0].content[0].text if hasattr(response.output[0].content[0], "text") else str(response.output)return answer or "Sorry, I couldn't generate a response."agent = BasicAgent()
app.py+25-16