Skip to content

Commit

Permalink
feat: Update Ollama default model to llama-3.2 (#554)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmigloz authored Sep 25, 2024
1 parent 41caed9 commit 016a231
Show file tree
Hide file tree
Showing 26 changed files with 78 additions and 78 deletions.
6 changes: 3 additions & 3 deletions docs/expression_language/primitives/router.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ First, let’s create a chain that will identify incoming questions as being abo

```dart
final chatModel = ChatOllama(
defaultOptions: ChatOllamaOptions(model: 'llama3.1'),
defaultOptions: ChatOllamaOptions(model: 'llama3.2'),
);
final classificationChain = PromptTemplate.fromTemplate('''
Expand Down Expand Up @@ -131,7 +131,7 @@ Here is a question:
{query}
''';
final embeddings = OllamaEmbeddings(model: 'llama3.1');
final embeddings = OllamaEmbeddings(model: 'llama3.2');
final promptTemplates = [physicsTemplate, historyTemplate];
final promptEmbeddings = await embeddings.embedDocuments(
promptTemplates.map((final pt) => Document(pageContent: pt)).toList(),
Expand All @@ -146,7 +146,7 @@ final chain = Runnable.fromMap<String>({'query': Runnable.passthrough()}) |
return PromptTemplate.fromTemplate(promptTemplates[mostSimilarIndex]);
}) |
ChatOllama(
defaultOptions: const ChatOllamaOptions(model: 'llama3.1'),
defaultOptions: const ChatOllamaOptions(model: 'llama3.2'),
) |
StringOutputParser();
Expand Down
4 changes: 2 additions & 2 deletions docs/modules/agents/agent_types/tools_agent.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ You can use any chat model that supports tool calling, like `ChatOpenAI`, `ChatO

## Usage

In the following example, we use `ChatOllama` with the `llama3.1` model and a calculator tool (included in `langchain_community`) to calculate the result of a mathematical expression.
In the following example, we use `ChatOllama` with the `llama3.2` model and a calculator tool (included in `langchain_community`) to calculate the result of a mathematical expression.

```dart
import 'package:langchain/langchain.dart';
Expand All @@ -20,7 +20,7 @@ import 'package:langchain_ollama/langchain_ollama.dart';
final llm = ChatOllama(
defaultOptions: ChatOllamaOptions(
model: 'llama3.1',
model: 'llama3.2',
temperature: 0,
),
);
Expand Down
26 changes: 13 additions & 13 deletions docs/modules/model_io/models/chat_models/integrations/ollama.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ Follow [these instructions](https://github.com/jmorganca/ollama) to set up and r

1. Download and install [Ollama](https://ollama.ai)
2. Fetch a model via `ollama pull <model family>`
* e.g., for Llama 3: `ollama pull llama3.1`
* e.g., for Llama 3: `ollama pull llama3.2`
3. Instantiate the `ChatOllama` class with the downloaded model.

```dart
final chatModel = ChatOllama(
defaultOptions: ChatOllamaOptions(
model: 'llama3.1',
model: 'llama3.2',
),
);
```
Expand All @@ -33,7 +33,7 @@ By default, `ChatOllama` uses 'http://localhost:11434/api' as base URL (default
final chatModel = ChatOllama(
defaultOptions: ChatOllamaOptions(
baseUrl: 'https://your-remote-server-where-ollama-is-running.com',
model: 'llama3.1',
model: 'llama3.2',
),
);
```
Expand All @@ -48,7 +48,7 @@ final promptTemplate = ChatPromptTemplate.fromTemplates([
final chatModel = ChatOllama(
defaultOptions: ChatOllamaOptions(
model: 'llama3.1',
model: 'llama3.2',
temperature: 0,
),
);
Expand All @@ -75,7 +75,7 @@ final promptTemplate = ChatPromptTemplate.fromTemplates([
]);
final chat = ChatOllama(
defaultOptions: ChatOllamaOptions(
model: 'llama3.1',
model: 'llama3.2',
temperature: 0,
),
);
Expand Down Expand Up @@ -123,8 +123,8 @@ print(res.output.content);
**Notes:**
- Tool calling requires [Ollama 0.3.0](https://github.com/ollama/ollama/releases/tag/v0.3.0) or newer.
- Streaming tool calls is not supported at the moment.
- Not all models support tool calls. Check the Ollama catalogue for models that have the `Tools` tag (e.g. [`llama3.1`](https://ollama.com/library/llama3.1) or [`llama3-groq-tool-use`](https://ollama.com/library/llama3-groq-tool-use)).
- At the moment, small models like `llama3.1` [cannot reliably maintain a conversation alongside tool calling definitions](https://llama.meta.com/docs/model-cards-and-prompt-formats/llama3_1/#llama-3.1-instruct). They can be used for zero-shot tool calling, but for multi-turn conversations it's recommended to use larger models like `llama3.1:70b` or `llama3.1:405b`.
- Not all models support tool calls. Check the Ollama catalogue for models that have the `Tools` tag (e.g. [`llama3.2`](https://ollama.com/library/llama3.2) or [`llama3-groq-tool-use`](https://ollama.com/library/llama3-groq-tool-use)).
- At the moment, small models like `llama3.2` [cannot reliably maintain a conversation alongside tool calling definitions](https://llama.meta.com/docs/model-cards-and-prompt-formats/llama3_1/#llama-3.1-instruct). They can be used for zero-shot tool calling, but for multi-turn conversations it's recommended to use larger models like `llama3.2:70b` or `llama3.2:405b`.

```dart
const tool = ToolSpec(
Expand All @@ -144,7 +144,7 @@ const tool = ToolSpec(
final chatModel = ChatOllama(
defaultOptions: ChatOllamaOptions(
model: 'llama3.1',
model: 'llama3.2',
temperature: 0,
tools: [tool],
),
Expand Down Expand Up @@ -173,7 +173,7 @@ If you want to customize how the model should respond to tool calls, you can use
```dart
final chatModel = ChatOllama(
defaultOptions: ChatOllamaOptions(
model: 'llama3.1',
model: 'llama3.2',
temperature: 0,
tools: [tool],
toolChoice: ChatToolChoice.forced(name: 'get_current_weather'),
Expand All @@ -194,7 +194,7 @@ final promptTemplate = ChatPromptTemplate.fromTemplates(const [
]);
final chat = ChatOllama(
defaultOptions: ChatOllamaOptions(
model: 'llama3.1',
model: 'llama3.2',
temperature: 0,
format: OllamaResponseFormat.json,
),
Expand Down Expand Up @@ -284,7 +284,7 @@ const getFlightTimesTool = ToolSpec(
final chatModel = ChatOllama(
defaultOptions: const ChatOllamaOptions(
model: 'llama3.1',
model: 'llama3.2',
temperature: 0,
tools: [getFlightTimesTool],
),
Expand Down Expand Up @@ -370,7 +370,7 @@ const tool = ToolSpec(
final model = ChatOllama(
defaultOptions: ChatOllamaOptions(
options: ChatOllamaOptions(
model: 'llama3.1',
model: 'llama3.2',
temperature: 0,
),
tools: [tool],
Expand Down Expand Up @@ -436,7 +436,7 @@ final promptTemplate = ChatPromptTemplate.fromTemplates([
// 3. Define the model to use and the vector store retriever
final chatModel = ChatOllama(
defaultOptions: ChatOllamaOptions(model: 'llama3.1'),
defaultOptions: ChatOllamaOptions(model: 'llama3.2'),
);
final retriever = vectorStore.asRetriever(
defaultOptions: VectorStoreRetrieverOptions(
Expand Down
6 changes: 3 additions & 3 deletions docs/modules/model_io/models/llms/integrations/ollama.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Follow [these instructions](https://github.com/jmorganca/ollama) to set up and r

1. Download and install [Ollama](https://ollama.ai)
2. Fetch a model via `ollama pull <model family>`
* e.g., for Llama 3: `ollama pull llama3.1`
* e.g., for Llama 3: `ollama pull llama3.2`

## Usage

Expand All @@ -26,7 +26,7 @@ final prompt = PromptTemplate.fromTemplate(
);
final llm = Ollama(
defaultOptions: OllamaOptions(
model: 'llama3.1',
model: 'llama3.2',
),
);
final chain = prompt | llm | StringOutputParser();
Expand All @@ -43,7 +43,7 @@ final promptTemplate = PromptTemplate.fromTemplate(
);
final llm = Ollama(
defaultOptions: OllamaOptions(
model: 'llama3.1',
model: 'llama3.2',
),
);
final chain = promptTemplate | llm | StringOutputParser();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# OllamaEmbeddings

```dart
final embeddings = OllamaEmbeddings(model: 'llama3.1');
final embeddings = OllamaEmbeddings(model: 'llama3.2');
const text = 'This is a test document.';
final res = await embeddings.embedQuery(text);
final res = await embeddings.embedDocuments([text]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ Sources:
// 6. Define the model to use and the vector store retriever
final chatModel = ChatOllama(
defaultOptions: ChatOllamaOptions(model: 'llama3.1'),
defaultOptions: ChatOllamaOptions(model: 'llama3.2'),
);
final retriever = vectorStore.asRetriever();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ void main(final List<String> arguments) async {

Future<void> _runnableRouter() async {
final chatModel = ChatOllama(
defaultOptions: const ChatOllamaOptions(model: 'llama3.1'),
defaultOptions: const ChatOllamaOptions(model: 'llama3.2'),
);

final classificationChain = PromptTemplate.fromTemplate('''
Expand Down Expand Up @@ -114,7 +114,7 @@ Here is a question:
''';

final embeddings = OllamaEmbeddings(
model: 'llama3.1',
model: 'llama3.2',
);
final promptTemplates = [physicsTemplate, historyTemplate];
final promptEmbeddings = await embeddings.embedDocuments(
Expand All @@ -132,7 +132,7 @@ Here is a question:
return PromptTemplate.fromTemplate(promptTemplates[mostSimilarIndex]);
}) |
ChatOllama(
defaultOptions: const ChatOllamaOptions(model: 'llama3.1'),
defaultOptions: const ChatOllamaOptions(model: 'llama3.2'),
) |
const StringOutputParser();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void main() async {
Future<void> _toolsAgent() async {
final llm = ChatOllama(
defaultOptions: const ChatOllamaOptions(
model: 'llama3.1',
model: 'llama3.2',
temperature: 0,
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Future<void> _chatOllama() async {

final chatModel = ChatOllama(
defaultOptions: const ChatOllamaOptions(
model: 'llama3.1',
model: 'llama3.2',
temperature: 0,
),
);
Expand All @@ -54,7 +54,7 @@ Future<void> _chatOllamaStreaming() async {
]);
final chat = ChatOllama(
defaultOptions: const ChatOllamaOptions(
model: 'llama3.1',
model: 'llama3.2',
temperature: 0,
),
);
Expand Down Expand Up @@ -109,7 +109,7 @@ Future<void> _chatOllamaToolCalling() async {

final chatModel = ChatOllama(
defaultOptions: const ChatOllamaOptions(
model: 'llama3.1',
model: 'llama3.2',
temperature: 0,
tools: [tool],
),
Expand Down Expand Up @@ -143,7 +143,7 @@ Future<void> _chatOllamaJsonMode() async {
]);
final chat = ChatOllama(
defaultOptions: const ChatOllamaOptions(
model: 'llama3.1',
model: 'llama3.2',
temperature: 0,
format: OllamaResponseFormat.json,
),
Expand Down Expand Up @@ -197,7 +197,7 @@ Future<void> _extraction() async {

final model = ChatOllama(
defaultOptions: ChatOllamaOptions(
model: 'llama3.1',
model: 'llama3.2',
temperature: 0,
tools: const [tool],
toolChoice: ChatToolChoice.forced(name: tool.name),
Expand Down Expand Up @@ -300,7 +300,7 @@ Future<void> _flights() async {

final chatModel = ChatOllama(
defaultOptions: const ChatOllamaOptions(
model: 'llama3.1',
model: 'llama3.2',
temperature: 0,
tools: [getFlightTimesTool],
),
Expand Down Expand Up @@ -370,7 +370,7 @@ Future<void> _rag() async {

// 3. Define the model to use and the vector store retriever
final chatModel = ChatOllama(
defaultOptions: const ChatOllamaOptions(model: 'llama3.1'),
defaultOptions: const ChatOllamaOptions(model: 'llama3.2'),
);
final retriever = vectorStore.asRetriever(
defaultOptions: const VectorStoreRetrieverOptions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Future<void> _ollama() async {
);
final llm = Ollama(
defaultOptions: const OllamaOptions(
model: 'llama3.1',
model: 'llama3.2',
),
);

Expand All @@ -29,7 +29,7 @@ Future<void> _ollamaStreaming() async {
);
final llm = Ollama(
defaultOptions: const OllamaOptions(
model: 'llama3.1',
model: 'llama3.2',
),
);
const stringOutputParser = StringOutputParser<LLMResult>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Sources:

// 6. Define the model to use and the vector store retriever
final chatModel = ChatOllama(
defaultOptions: const ChatOllamaOptions(model: 'llama3.1'),
defaultOptions: const ChatOllamaOptions(model: 'llama3.2'),
);
final retriever = vectorStore.asRetriever();

Expand Down
2 changes: 1 addition & 1 deletion examples/hello_world_flutter/lib/home/bloc/providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ enum Provider {
),
ollama(
name: 'Ollama',
defaultModel: 'llama3.1',
defaultModel: 'llama3.2',
defaultBaseUrl: 'http://localhost:11434/api',
isRemote: false,
);
Expand Down
6 changes: 3 additions & 3 deletions examples/wikivoyage_eu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ This example demonstrates how to build a fully local Retrieval Augmented Generat

- For this example we will be using the following models:
* Embedding model: [`jina/jina-embeddings-v2-small-en`](https://ollama.com/jina/jina-embeddings-v2-small-en)
* LLM: [`llama3.1`](https://ollama.com/library/llama3.1)
* LLM: [`llama3.2`](https://ollama.com/library/llama3.2)
- Open your terminal and run:
```bash
ollama pull jina/jina-embeddings-v2-small-en
ollama run llama3.1
ollama run llama3.2
```

### 3. Setup ObjectBox
Expand Down Expand Up @@ -73,7 +73,7 @@ The chatbot script implements the RAG pipeline. It does the following:
2. Uses the `jina/jina-embeddings-v2-small-en` model to create an embedding for the query.
3. Retrieves the 5 most similar documents from the ObjectBox database.
4. Builds a prompt using the retrieved documents and the query.
5. Uses the `llama3.1` model to generate a response to the prompt.
5. Uses the `llama3.2` model to generate a response to the prompt.

You can run the script using:
```bash
Expand Down
2 changes: 1 addition & 1 deletion examples/wikivoyage_eu/bin/wikivoyage_eu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Do not provide any other suggestion if the question is not about Europe.

final model = ChatOllama(
defaultOptions: const ChatOllamaOptions(
model: 'llama3.1',
model: 'llama3.2',
),
);
const outputParser = StringOutputParser<ChatResult>();
Expand Down
2 changes: 1 addition & 1 deletion examples/wikivoyage_eu/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: wikivoyage_eu
description: Wikivoyage EU chatbot using llama3.1 and ObjectBox.
description: Wikivoyage EU chatbot using llama3.2 and ObjectBox.
version: 1.0.0
publish_to: none

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import 'types.dart';
/// Vector store for the [ObjectBox](https://objectbox.io/) on-device database.
///
/// ```dart
/// final embeddings = OllamaEmbeddings(model: 'llama3.1');
/// final embeddings = OllamaEmbeddings(model: 'llama3.2');
/// final vectorStore = ObjectBoxVectorStore(embeddings: embeddings);
/// ```
///
Expand Down
Loading

0 comments on commit 016a231

Please sign in to comment.