Releases: vercel/modelfusion
v0.105.0
Added
-
Tool call support for chat prompts. Assistant messages can contain tool calls, and tool messages can contain tool call results. Tool calls can be used to implement e.g. agents:
const chat: ChatPrompt = { system: "You are ...", messages: [ChatMessage.user({ text: instruction })], }; while (true) { const { text, toolResults } = await useToolsOrGenerateText( openai .ChatTextGenerator({ model: "gpt-4-1106-preview" }) .withChatPrompt(), tools, // array of tools chat ); // add the assistant and tool messages to the chat: chat.messages.push( ChatMessage.assistant({ text, toolResults }), ChatMessage.tool({ toolResults }) ); if (toolResults == null) { return; // no more actions, break loop } // ... (handle tool results) }
-
streamText
returns atext
promise when invoked withfullResponse: true
. After the streaming has finished, the promise resolves with the full text.const { text, textStream } = await streamText( openai.ChatTextGenerator({ model: "gpt-3.5-turbo" }).withTextPrompt(), "Write a short story about a robot learning to love:", { fullResponse: true } ); // ... (handle streaming) console.log(await text); // full text
v0.104.0
Changed
- breaking change: Unified text and multimodal prompt templates.
[Text/MultiModal]InstructionPrompt
is nowInstructionPrompt
, and[Text/MultiModalChatPrompt]
is nowChatPrompt
. - More flexible chat prompts: The chat prompt validation is now chat template specific and validated at runtime. E.g. the Llama2 prompt template only supports turns of user and assistant messages, whereas other formats are more flexible.
v0.103.0
Added
-
finishReason
support forgenerateText
.The finish reason can be
stop
(the model stopped because it generated a stop sequence),length
(the model stopped because it generated the maximum number of tokens),content-filter
(the model stopped because the content filter detected a violation),tool-calls
(the model stopped because it triggered a tool call),error
(the model stopped because of an error),other
(the model stopped for another reason), orunknown
(the model stop reason is not know or the model does not support finish reasons).You can extract it from the full response when using
fullResponse: true
:const { text, finishReason } = await generateText( openai .ChatTextGenerator({ model: "gpt-3.5-turbo", maxGenerationTokens: 200 }) .withTextPrompt(), "Write a short story about a robot learning to love:", { fullResponse: true } );
v0.102.0
Added
-
You can specify
numberOfGenerations
on image generation models and create multiple images by using thefullResponse: true
option. Example:// generate 2 images: const { images } = await generateImage( openai.ImageGenerator({ model: "dall-e-3", numberOfGenerations: 2, size: "1024x1024", }), "the wicked witch of the west in the style of early 19th century painting", { fullResponse: true } );
-
breaking change: Image generation models use a generalized
numberOfGenerations
parameter (instead of model specific parameters) to specify the number of generations.
v0.101.0
v0.100.0
v0.100.0 - 2023-12-17
Added
ollama.ChatTextGenerator
model that calls the Ollama chat API.- Ollama chat messages and prompts are exposed through
ollama.ChatMessage
andollama.ChatPrompt
- OpenAI chat messages and prompts are exposed through
openai.ChatMessage
andopenai.ChatPrompt
- Mistral chat messages and prompts are exposed through
mistral.ChatMessage
andmistral.ChatPrompt
Changed
- breaking change: renamed
ollama.TextGenerator
toollama.CompletionTextGenerator
- breaking change: renamed
mistral.TextGenerator
tomistral.ChatTextGenerator
v0.99.0
Added
-
You can now specify
numberOfGenerations
on text generation models and access multiple generations by using thefullResponse: true
option. Example:// generate 2 texts: const { texts } = await generateText( openai.CompletionTextGenerator({ model: "gpt-3.5-turbo-instruct", numberOfGenerations: 2, maxGenerationTokens: 1000, }), "Write a short story about a robot learning to love:\n\n", { fullResponse: true } );
-
breaking change: Text generation models now use a generalized
numberOfGenerations
parameter (instead of model specific parameters) to specify the number of generations.
Changed
- breaking change: Renamed
maxCompletionTokens
text generation model setting tomaxGenerationTokens
.
v0.98.0
Changed
-
breaking change:
responseType
option was changed intofullResponse
option and now uses a boolean value to make discovery easy. The response values from the full response have been renamed for clarity. For base64 image generation, you can use theimageBase64
value from the full response:const { imageBase64 } = await generateImage(model, prompt, { fullResponse: true, });
Improved
- Better docs for the OpenAI chat settings. Thanks @bearjaws for the contribution!
Fixed
- Streaming OpenAI chat text generation when setting
n:2
or higher now returns only the stream from the first choice.
v0.97.0
Added
-
breaking change: Ollama image (vision) support. This changes the Ollama prompt format. You can add
.withTextPrompt()
to existing Ollama text generators to get a text prompt like before.Vision example:
import { ollama, streamText } from "modelfusion"; const textStream = await streamText( ollama.TextGenerator({ model: "bakllava", maxCompletionTokens: 1024, temperature: 0, }), { prompt: "Describe the image in detail", images: [image], // base-64 encoded png or jpeg } );
Changed
- breaking change: Switch Ollama settings to camelCase to align with the rest of the library.