Skip to content

Commit

Permalink
added fucntion calling for formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
shohey1226 committed Jun 26, 2023
1 parent b148ca3 commit e8ba82d
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions lib/llm_memory/broca.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,46 @@ def respond(args)
end
end

def respond_with_schema(context: {}, schema: {})
response_content = respond(context)
begin
response = client.chat(
parameters: {
model: @model,
messages: [
{
role: "user",
content: response_content
}
],
functions: [
{
name: "broca",
description: "Formating the content with the specified schema",
parameters: schema
}
]
}
)
LlmMemory.logger.debug(response)
message = response.dig("choices", 0, "message")
if message["role"] == "assistant" && message["function_call"]
function_name = message.dig("function_call", "name")
args =
JSON.parse(
message.dig("function_call", "arguments"),
{symbolize_names: true}
)
if function_name == "broca"
args
end
end
rescue => e
LlmMemory.logger.info(e.inspect)
nil
end
end

def generate_prompt(args)
erb = ERB.new(@prompt)
erb.result_with_hash(args)
Expand Down

0 comments on commit e8ba82d

Please sign in to comment.