Skip to content

Commit

Permalink
docs: update examples to reflect chat_completion/2 interface (#34)
Browse files Browse the repository at this point in the history
* docs: update examples to reflect `chat_completion/2` interface

* docs: update last occurence
  • Loading branch information
nickgnd authored Mar 16, 2024
1 parent 1e4d453 commit f137505
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
16 changes: 8 additions & 8 deletions lib/instructor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ defmodule Instructor do
## Examples
iex> Instructor.chat_completion(%{
iex> Instructor.chat_completion(
...> model: "gpt-3.5-turbo",
...> response_model: Instructor.Demos.SpamPrediction,
...> messages: [
...> %{
...> role: "user",
...> content: "Classify the following text: Hello, I am a Nigerian prince and I would like to give you $1,000,000."
...> }
...> })
...> ])
{:ok,
%Instructor.Demos.SpamPrediction{
class: :spam
Expand All @@ -55,15 +55,15 @@ defmodule Instructor do
Partial streaming will emit the record multiple times until it's complete.
iex> Instructor.chat_completion(%{
iex> Instructor.chat_completion(
...> model: "gpt-3.5-turbo",
...> response_model: {:partial, %{name: :string, birth_date: :date}}
...> messages: [
...> %{
...> role: "user",
...> content: "Who is the first president of the United States?"
...> }
...> }) |> Enum.to_list()
...> ]) |> Enum.to_list()
[
{:partial, %{name: "George Washington"}},
{:partial, %{name: "George Washington", birth_date: ~D[1732-02-22]}},
Expand All @@ -73,15 +73,15 @@ defmodule Instructor do
Whereas with array streaming, you can ask the LLM to return multiple instances of your Ecto schema,
and instructor will emit them one at a time as they arrive in complete form and validated.
iex> Instructor.chat_completion(%{
iex> Instructor.chat_completion(
...> model: "gpt-3.5-turbo",
...> response_model: {:array, %{name: :string, birth_date: :date}}
...> messages: [
...> %{
...> role: "user",
...> content: "Who are the first 5 presidents of the United States?"
...> }
...> }) |> Enum.to_list()
...> ]) |> Enum.to_list()
[
{:ok, %{name: "George Washington", birth_date: ~D[1732-02-22]}},
Expand All @@ -93,15 +93,15 @@ defmodule Instructor do
If there's a validation error, it will return an error tuple with the change set describing the errors.
iex> Instructor.chat_completion(%{
iex> Instructor.chat_completion(
...> model: "gpt-3.5-turbo",
...> response_model: Instructor.Demos.SpamPrediction,
...> messages: [
...> %{
...> role: "user",
...> content: "Classify the following text: Hello, I am a Nigerian prince and I would like to give you $1,000,000."
...> }
...> })
...> ])
{:error,
%Ecto.Changeset{
changes: %{
Expand Down
4 changes: 2 additions & 2 deletions lib/instructor/adapters/llamacpp.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ defmodule Instructor.Adapters.Llamacpp do
## Examples
iex> Instructor.chat_completion(%{
iex> Instructor.chat_completion(
...> model: "mistral-7b-instruct",
...> messages: [
...> %{ role: "user", content: "Classify the following text: Hello I am a Nigerian prince and I would like to send you money!" },
...> ],
...> response_model: response_model,
...> temperature: 0.5,
...> })
...> )
"""
@impl true
def chat_completion(params, _config \\ nil) do
Expand Down
4 changes: 2 additions & 2 deletions lib/instructor/validator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ defmodule Instructor.Validator do
end
end
iex> Instructor.chat_completion(%{
iex> Instructor.chat_completion(
...> model: "gpt-3.5-turbo",
...> response_model: Instructor.Demos.SpamPrediction,
...> max_retries: 1,
Expand All @@ -31,7 +31,7 @@ defmodule Instructor.Validator do
...> role: "user",
...> content: "Classify the following text: Hello, I am a Nigerian prince and I would like to give you $1,000,000."
...> }
...> })
...> ])
{:error, %Ecto.Changeset{
action: nil,
changes: %{},
Expand Down

0 comments on commit f137505

Please sign in to comment.