Skip to content

Commit

Permalink
potentially fix anthropic
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljguarino committed Dec 12, 2024
1 parent a62e895 commit 0a4804a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion lib/console/ai/provider/anthropic.ex
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,14 @@ defmodule Console.AI.Anthropic do
case chat(anthropic, messages) do
{:ok, %MessageResponse{content: content}} ->
{:ok, format_content(content)}
{:ok, content} when is_binary(content) -> {:ok, content}
{:ok, _} -> {:error, "could not generate an ai completion for this context"}
error -> error
end
end

def tool_call(anthropic, messages, tools) do
case chat(anthropic, messages, tools) do
case chat(%{anthropic | stream: nil}, messages, tools) do
{:ok, %MessageResponse{content: [%Content{type: "tool_use"}] = tools}} ->
{:ok, gen_tools(tools)}
{:ok, %MessageResponse{content: content}} ->
Expand Down
4 changes: 2 additions & 2 deletions lib/console/ai/provider/azure.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ defmodule Console.AI.Azure do

require Logger

defstruct [:access_key, :api_version, :base_url, :model, :tool_model]
defstruct [:access_token, :api_version, :base_url, :model, :tool_model]

@api_vsn "2024-10-01-preview"

@type t :: %__MODULE__{}

def new(opts) do
%__MODULE__{
access_key: opts.access_key,
access_token: opts.access_key,
api_version: opts.api_version,
model: opts.model,
tool_model: opts.tool_model,
Expand Down
8 changes: 4 additions & 4 deletions lib/console/ai/provider/vertex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ defmodule Console.AI.Vertex do
@spec completion(t(), Console.AI.Provider.history) :: {:ok, binary} | Console.error
def completion(%__MODULE__{} = vertex, messages) do
with {:ok, %{token: token}} <- client(vertex) do
OpenAI.new(
OpenAI.new(%{
base_url: openai_url(vertex),
access_token: token,
model: openai_model(vertex),
tool_model: openai_model(vertex)
)
})
|> OpenAI.completion(messages)
end
end
Expand All @@ -47,12 +47,12 @@ defmodule Console.AI.Vertex do
@spec tool_call(t(), Console.AI.Provider.history, [atom]) :: {:ok, binary} | {:ok, [Console.AI.Tool.t]} | Console.error
def tool_call(%__MODULE__{} = vertex, messages, tools) do
with {:ok, %{token: token}} <- client(vertex) do
OpenAI.new(
OpenAI.new(%{
base_url: openai_url(vertex),
access_token: token,
model: openai_model(vertex),
tool_model: openai_model(vertex)
)
})
|> OpenAI.tool_call(messages, tools)
end
end
Expand Down

0 comments on commit 0a4804a

Please sign in to comment.