-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Compile time model selection, summarization
[FEATURE] Compile time model selection, summarization
- Loading branch information
Showing
9 changed files
with
226 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
defmodule Oli.Conversation.Common do | ||
def estimate_token_length(function) when is_map(function) do | ||
Jason.encode!(function) | ||
|> estimate_token_length() | ||
end | ||
|
||
def estimate_token_length(content) do | ||
String.length(content) |> div(4) | ||
end | ||
|
||
def summarize_prompt() do | ||
""" | ||
You are a converstational summarization agent that is tasked with summarizing long conversations between | ||
human users and a large language model conversational agent. Your primary goal is to summarize the conversation | ||
into a single "summary" paragraph of no longer that 5 or 6 sentences which captures the essence of the conversation. | ||
You are given a conversation below as a series of "assistant" and "user" messages. You can summarize the conversation | ||
along the lines of "user asked about X. Assistant responded with Y. User asked about Z. Assistant responded with A. etc" | ||
""" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
defmodule Oli.Conversation.Functions do | ||
import Oli.Conversation.Common | ||
|
||
@functions [ | ||
%{ | ||
name: "up_next", | ||
description: | ||
"Returns the next scheduled lessons in the course as a list of objects with the following keys: title, url, due_date, num_attempts_taken", | ||
parameters: %{ | ||
type: "object", | ||
properties: %{ | ||
current_user_id: %{ | ||
type: "integer", | ||
description: "The current student's user id" | ||
}, | ||
section_id: %{ | ||
type: "integer", | ||
description: "The current course section's id" | ||
} | ||
}, | ||
required: ["current_user_id", "section_id"] | ||
} | ||
}, | ||
%{ | ||
name: "avg_score_for", | ||
description: | ||
"Returns average score across all scored assessments, as a floating point number between 0 and 1, for a given user and section", | ||
parameters: %{ | ||
type: "object", | ||
properties: %{ | ||
current_user_id: %{ | ||
type: "integer", | ||
description: "The current student's user id" | ||
}, | ||
section_id: %{ | ||
type: "integer", | ||
description: "The current course section's id" | ||
} | ||
}, | ||
required: ["current_user_id", "section_id"] | ||
} | ||
}, | ||
%{ | ||
name: "relevant_course_content", | ||
description: """ | ||
Useful when a question asked by a student cannot be adequately answered by the context of the current lesson. | ||
Allows the retrieval of relevant course content from other lessons in the course based on the | ||
student's question. Returns an array of course lessons with the following keys: title, url, content. | ||
""", | ||
parameters: %{ | ||
type: "object", | ||
properties: %{ | ||
student_input: %{ | ||
type: "string", | ||
description: "The student question or input" | ||
}, | ||
section_id: %{ | ||
type: "integer", | ||
description: "The current course section's id" | ||
} | ||
}, | ||
required: ["student_input", "section_id"] | ||
} | ||
} | ||
] | ||
|
||
def functions, do: @functions | ||
|
||
def total_token_length, | ||
do: Enum.reduce(@functions, 0, fn f, acc -> acc + estimate_token_length(f) end) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,28 @@ | ||
defmodule Oli.Conversation.Message do | ||
import Oli.Conversation.Common | ||
|
||
@derive Jason.Encoder | ||
defstruct [ | ||
:role, | ||
:content, | ||
:name | ||
:name, | ||
:token_length | ||
] | ||
|
||
def new(role, content) do | ||
%__MODULE__{ | ||
role: role, | ||
content: content | ||
content: content, | ||
token_length: estimate_token_length(content) | ||
} | ||
end | ||
|
||
def new(role, content, name) do | ||
%__MODULE__{ | ||
role: role, | ||
content: content, | ||
name: name | ||
name: name, | ||
token_length: estimate_token_length(content) | ||
} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
defmodule Oli.Conversation.Model do | ||
@default_model :fast | ||
|
||
def default(), do: @default_model | ||
|
||
def model(:fast), do: "gpt-3.5-turbo" | ||
def model(:large_context), do: "gpt-4" | ||
def model(:largest_context), do: "gpt-4-1106-preview" | ||
|
||
def token_limit("gpt-3.5-turbo"), do: 4096 | ||
def token_limit("gpt-4"), do: 8192 | ||
def token_limit("gpt-4-1106-preview"), do: 128_000 | ||
|
||
def token_limit(atom) when is_atom(atom) do | ||
model(atom) | ||
|> token_limit() | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.