mirror of
https://github.com/arc53/DocsGPT.git
synced 2025-11-29 16:43:16 +00:00
fix: google parser, llm handler and other errors
This commit is contained in:
@@ -47,23 +47,43 @@ class OpenAILLMHandler(LLMHandler):
|
||||
|
||||
class GoogleLLMHandler(LLMHandler):
|
||||
def handle_response(self, agent, resp, tools_dict, messages):
|
||||
from google.genai import types
|
||||
import google.generativeai as genai
|
||||
|
||||
while resp.content.parts[0].function_call:
|
||||
function_call_part = resp.candidates[0].content.parts[0]
|
||||
tool_response, call_id = agent._execute_tool_action(
|
||||
tools_dict, function_call_part.function_call
|
||||
)
|
||||
function_response_part = types.Part.from_function_response(
|
||||
name=function_call_part.function_call.name, response=tool_response
|
||||
)
|
||||
|
||||
messages.append(function_call_part, function_response_part)
|
||||
while (
|
||||
hasattr(resp.candidates[0].content.parts[0], "function_call")
|
||||
and resp.candidates[0].content.parts[0].function_call
|
||||
):
|
||||
responses = {}
|
||||
for part in resp.candidates[0].content.parts:
|
||||
if hasattr(part, "function_call") and part.function_call:
|
||||
function_call_part = part
|
||||
messages.append(
|
||||
genai.protos.Part(
|
||||
function_call=genai.protos.FunctionCall(
|
||||
name=function_call_part.function_call.name,
|
||||
args=function_call_part.function_call.args,
|
||||
)
|
||||
)
|
||||
)
|
||||
tool_response, call_id = agent._execute_tool_action(
|
||||
tools_dict, function_call_part.function_call
|
||||
)
|
||||
responses[function_call_part.function_call.name] = tool_response
|
||||
response_parts = [
|
||||
genai.protos.Part(
|
||||
function_response=genai.protos.FunctionResponse(
|
||||
name=tool_name, response={"result": response}
|
||||
)
|
||||
)
|
||||
for tool_name, response in responses.items()
|
||||
]
|
||||
if response_parts:
|
||||
messages.append(response_parts)
|
||||
resp = agent.llm.gen(
|
||||
model=agent.gpt_model, messages=messages, tools=agent.tools
|
||||
)
|
||||
|
||||
return resp
|
||||
return resp.text
|
||||
|
||||
|
||||
def get_llm_handler(llm_type):
|
||||
|
||||
Reference in New Issue
Block a user