Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Update Ollama default model from llama2 to llama3 #417

Merged
merged 1 commit into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 21 additions & 25 deletions docs/modules/model_io/models/chat_models/integrations/ollama.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Wrapper around [Ollama](https://ollama.ai) Completions API that enables to interact with the LLMs in a chat-like fashion.

Ollama allows you to run open-source large language models, such as Llama 2, locally.
Ollama allows you to run open-source large language models, such as Llama 3, locally.

Ollama bundles model weights, configuration, and data into a single package, defined by a Modelfile.

Expand All @@ -16,22 +16,19 @@ 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-7b`: `ollama pull llama2`
* e.g., for Llama 3: `ollama pull llama3`

## Usage

```dart
final promptTemplate = ChatPromptTemplate.fromTemplates([
(
ChatMessageType.system,
'You are a helpful assistant that translates {input_language} to {output_language}.',
),
(ChatMessageType.system, 'You are a helpful assistant that translates {input_language} to {output_language}.'),
(ChatMessageType.human, '{text}'),
]);

final chatModel = ChatOllama(
defaultOptions: ChatOllamaOptions(
model: 'llama2',
model: 'llama3',
temperature: 0,
),
);
Expand All @@ -51,16 +48,12 @@ print(res);

```dart
final promptTemplate = ChatPromptTemplate.fromTemplates([
(
ChatMessageType.system,
'You are a helpful assistant that replies only with numbers '
'in order without any spaces or commas',
),
(ChatMessageType.human, 'List the numbers from 1 to {max_num}'),
(ChatMessageType.system, 'You are a helpful assistant that replies only with numbers in order without any spaces or commas'),
(ChatMessageType.human, 'List the numbers from 1 to {max_num}'),
]);
final chat = ChatOllama(
defaultOptions: ChatOllamaOptions(
model: 'llama2',
model: 'llama3',
temperature: 0,
),
);
Expand All @@ -77,28 +70,31 @@ await stream.forEach(print);

## JSON mode

You can enforce the model to produce a JSON output, useful for extracting structured data.
You can force the model to produce JSON output that you can easily parse using `JsonOutputParser`, useful for extracting structured data.

```dart
final promptTemplate = ChatPromptTemplate.fromTemplates(const [
(ChatMessageType.system, 'Respond using JSON'),
(ChatMessageType.system, 'You are an assistant that respond question using JSON format.'),
(ChatMessageType.human, '{question}'),
]);
final chat = ChatOllama(
defaultOptions: const ChatOllamaOptions(
model: 'llama2',
defaultOptions: ChatOllamaOptions(
model: 'llama3',
temperature: 0,
format: OllamaResponseFormat.json,
),
);

final chain = promptTemplate.pipe(chat);
final chain = Runnable.getMapFromInput<String>('question')
.pipe(promptTemplate)
.pipe(chat)
.pipe(JsonOutputParser());

final res = await chain.invoke(
{'question': 'What color is the sky at different times of the day?'},
'What is the population of Spain, The Netherlands, and France?',
);
print(res.output.content);
// {"morning": {"sky": "pink", "sun": "rise"}, "daytime": {"sky": "blue", "sun": "high"}, "afternoon": ...}
print(res);
// {Spain: 46735727, The Netherlands: 17398435, France: 65273538}
```

## Multimodal support
Expand All @@ -109,7 +105,7 @@ You can provide several base64-encoded `png` or `jpeg` images. Images up to 100M

```dart
final chatModel = ChatOllama(
defaultOptions: const ChatOllamaOptions(
defaultOptions: ChatOllamaOptions(
model: 'llava',
temperature: 0,
),
Expand All @@ -136,7 +132,7 @@ We can easily create a fully local RAG pipeline using `OllamaEmbeddings` and `Ch
```dart
// 1. Create a vector store and add documents to it
final vectorStore = MemoryVectorStore(
embeddings: OllamaEmbeddings(model: 'llama2'),
embeddings: OllamaEmbeddings(model: 'llama3'),
);
await vectorStore.addDocuments(
documents: [
Expand All @@ -153,7 +149,7 @@ final promptTemplate = ChatPromptTemplate.fromTemplates([

// 3. Define the model to use and the vector store retriever
final chatModel = ChatOllama(
defaultOptions: ChatOllamaOptions(model: 'llama2'),
defaultOptions: ChatOllamaOptions(model: 'llama3'),
);
final retriever = vectorStore.asRetriever(
defaultOptions: VectorStoreRetrieverOptions(
Expand Down
17 changes: 8 additions & 9 deletions docs/modules/model_io/models/llms/integrations/ollama.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Wrapper around [Ollama](https://ollama.ai) Completions API.

Ollama allows you to run open-source large language models, such as Llama 2, locally.
Ollama allows you to run open-source large language models, such as Llama 3, locally.

Ollama bundles model weights, configuration, and data into a single package, defined by a Modelfile.

Expand All @@ -12,11 +12,11 @@ For a complete list of supported models and model variants, see the [Ollama mode

## Setup

Rollow [these instructions](https://github.com/jmorganca/ollama) to set up and run a local Ollama instance:
Follow [these instructions](https://github.com/jmorganca/ollama) to set up and run a local Ollama instance:

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

## Usage

Expand All @@ -25,8 +25,8 @@ final prompt = PromptTemplate.fromTemplate(
'What is a good name for a company that makes {product}?',
);
final llm = Ollama(
defaultOptions: const OllamaOptions(
model: 'llama2',
defaultOptions: OllamaOptions(
model: 'llama3',
),
);
final chain = prompt | llm | StringOutputParser();
Expand All @@ -42,12 +42,11 @@ final promptTemplate = PromptTemplate.fromTemplate(
'List the numbers from 1 to {max_num} in order without any spaces or commas',
);
final llm = Ollama(
defaultOptions: const OllamaOptions(
model: 'llama2',
defaultOptions: OllamaOptions(
model: 'llama3',
),
);
const stringOutputParser = StringOutputParser<LLMResult>();
final chain = promptTemplate | llm | stringOutputParser;
final chain = promptTemplate | llm | StringOutputParser();
final stream = chain.stream({'max_num': '9'});
await stream.forEach(print);
// 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# OllamaEmbeddings

```dart
final embeddings = OllamaEmbeddings(model: 'llama2');
final embeddings = OllamaEmbeddings(model: 'llama3');
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 @@ -24,7 +24,7 @@ Future<void> _chatOllama() async {

final chatModel = ChatOllama(
defaultOptions: const ChatOllamaOptions(
model: 'llama2',
model: 'llama3',
temperature: 0,
),
);
Expand All @@ -51,7 +51,7 @@ Future<void> _chatOllamaStreaming() async {
]);
final chat = ChatOllama(
defaultOptions: const ChatOllamaOptions(
model: 'llama2',
model: 'llama3',
temperature: 0,
),
);
Expand All @@ -68,24 +68,30 @@ Future<void> _chatOllamaStreaming() async {

Future<void> _chatOllamaJsonMode() async {
final promptTemplate = ChatPromptTemplate.fromTemplates(const [
(ChatMessageType.system, 'Respond using JSON'),
(
ChatMessageType.system,
'You are an assistant that respond question using JSON format.'
),
(ChatMessageType.human, '{question}'),
]);
final chat = ChatOllama(
defaultOptions: const ChatOllamaOptions(
model: 'llama2',
model: 'llama3',
temperature: 0,
format: OllamaResponseFormat.json,
),
);

final chain = promptTemplate.pipe(chat);
final chain = Runnable.getMapFromInput<String>('question')
.pipe(promptTemplate)
.pipe(chat)
.pipe(JsonOutputParser());

final res = await chain.invoke(
{'question': 'What color is the sky at different times of the day?'},
'What is the population of Spain, The Netherlands, and France?',
);
print(res.output.content);
// {"morning": {"sky": "pink", "sun": "rise"}, "daytime": {"sky": "blue", "sun": "high"}, "afternoon": ...}
print(res);
// {Spain: 46735727, The Netherlands: 17398435, France: 65273538}
}

Future<void> _chatOllamaMultimodal() async {
Expand Down Expand Up @@ -113,7 +119,7 @@ Future<void> _chatOllamaMultimodal() async {
Future<void> _rag() async {
// 1. Create a vector store and add documents to it
final vectorStore = MemoryVectorStore(
embeddings: OllamaEmbeddings(model: 'llama2'),
embeddings: OllamaEmbeddings(model: 'llama3'),
);
await vectorStore.addDocuments(
documents: [
Expand All @@ -135,7 +141,7 @@ Future<void> _rag() async {

// 3. Define the model to use and the vector store retriever
final chatModel = ChatOllama(
defaultOptions: const ChatOllamaOptions(model: 'llama2'),
defaultOptions: const ChatOllamaOptions(model: 'llama3'),
);
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: 'llama2',
model: 'llama3',
),
);

Expand All @@ -29,7 +29,7 @@ Future<void> _ollamaStreaming() async {
);
final llm = Ollama(
defaultOptions: const OllamaOptions(
model: 'llama2',
model: 'llama3',
),
);
const stringOutputParser = StringOutputParser<LLMResult>();
Expand Down
24 changes: 12 additions & 12 deletions packages/langchain/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@ LangChain.dart has a modular design that allows developers to import only the co
<img src="https://raw.githubusercontent.com/davidmigloz/langchain_dart/main/docs/img/langchain_packages.png" width="500">
</p>

| Package | Version | Description |
|---------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [langchain_core](https://pub.dev/packages/langchain_core) | [![langchain_core](https://img.shields.io/pub/v/langchain_core.svg)](https://pub.dev/packages/langchain_core) | Core abstractions and LCEL |
| [langchain](https://pub.dev/packages/langchain) | [![langchain](https://img.shields.io/pub/v/langchain.svg)](https://pub.dev/packages/langchain) | Higher-level and use-case specific chains, agents, and retrieval algorithms |
| [langchain_community](https://pub.dev/packages/langchain_community) | [![langchain_community](https://img.shields.io/pub/v/langchain_community.svg)](https://pub.dev/packages/langchain_community) | Third-party integrations (without specific packages) and community-contributed components |
| [langchain_openai](https://pub.dev/packages/langchain_openai) | [![langchain_openai](https://img.shields.io/pub/v/langchain_openai.svg)](https://pub.dev/packages/langchain_openai) | OpenAI integration (GPT-3.5, GPT-4, Embeddings, Functions, Vision, DALL·E 3, etc.) and OpenAI Compatible services (Together AI, Anyscale, OpenRouter, etc.) |
| [langchain_google](https://pub.dev/packages/langchain_google) | [![langchain_google](https://img.shields.io/pub/v/langchain_google.svg)](https://pub.dev/packages/langchain_google) | Google integration (GoogleAI, VertexAI, Gemini, PaLM 2, Embeddings, Vector Search, etc.) |
| [langchain_ollama](https://pub.dev/packages/langchain_ollama) | [![langchain_ollama](https://img.shields.io/pub/v/langchain_ollama.svg)](https://pub.dev/packages/langchain_ollama) | Ollama integration (Llama 2, Code Llama, Mistral, LLaVA, Phi, Vicuna, Orca, Starling, etc.) |
| [langchain_mistralai](https://pub.dev/packages/langchain_mistralai) | [![langchain_mistralai](https://img.shields.io/pub/v/langchain_mistralai.svg)](https://pub.dev/packages/langchain_mistralai) | Mistral AI integration (Mistral-7B, Mixtral 8x7B, embeddings, etc.). |
| [langchain_pinecone](https://pub.dev/packages/langchain_pinecone) | [![langchain_pinecone](https://img.shields.io/pub/v/langchain_pinecone.svg)](https://pub.dev/packages/langchain_pinecone) | Pinecone vector database integration |
| [langchain_chroma](https://pub.dev/packages/langchain_chroma) | [![langchain_chroma](https://img.shields.io/pub/v/langchain_chroma.svg)](https://pub.dev/packages/langchain_chroma) | Chroma vector database integration |
| [langchain_supabase](https://pub.dev/packages/langchain_supabase) | [![langchain_supabase](https://img.shields.io/pub/v/langchain_supabase.svg)](https://pub.dev/packages/langchain_supabase) | Supabase Vector database integration |
| Package | Version | Description |
|---------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [langchain_core](https://pub.dev/packages/langchain_core) | [![langchain_core](https://img.shields.io/pub/v/langchain_core.svg)](https://pub.dev/packages/langchain_core) | Core abstractions and LCEL |
| [langchain](https://pub.dev/packages/langchain) | [![langchain](https://img.shields.io/pub/v/langchain.svg)](https://pub.dev/packages/langchain) | Higher-level and use-case specific chains, agents, and retrieval algorithms |
| [langchain_community](https://pub.dev/packages/langchain_community) | [![langchain_community](https://img.shields.io/pub/v/langchain_community.svg)](https://pub.dev/packages/langchain_community) | Third-party integrations (without specific packages) and community-contributed components |
| [langchain_openai](https://pub.dev/packages/langchain_openai) | [![langchain_openai](https://img.shields.io/pub/v/langchain_openai.svg)](https://pub.dev/packages/langchain_openai) | OpenAI integration (GPT-3.5 Turbo, GPT-4, GPT-4 Turbo, Embeddings, Tools, Vision, DALL·E 3, etc.) and OpenAI Compatible services (TogetherAI, Anyscale, OpenRouter, One API, Groq, Llamafile, GPT4All, etc.) |
| [langchain_google](https://pub.dev/packages/langchain_google) | [![langchain_google](https://img.shields.io/pub/v/langchain_google.svg)](https://pub.dev/packages/langchain_google) | Google integration (GoogleAI, VertexAI, Gemini, PaLM 2, Embeddings, Vector Search, etc.) |
| [langchain_ollama](https://pub.dev/packages/langchain_ollama) | [![langchain_ollama](https://img.shields.io/pub/v/langchain_ollama.svg)](https://pub.dev/packages/langchain_ollama) | Ollama integration (Llama 3, Phi-3, WizardLM-2, Mistral 7B, Gemma, CodeGemma, Command R, LLaVA, DBRX, Qwen 1.5, Dolphin, DeepSeek Coder, Vicuna, Orca, etc.) |
| [langchain_mistralai](https://pub.dev/packages/langchain_mistralai) | [![langchain_mistralai](https://img.shields.io/pub/v/langchain_mistralai.svg)](https://pub.dev/packages/langchain_mistralai) | Mistral AI integration (Mistral-7B, Mixtral 8x7B, Mixtral 8x22B, Mistral Small, Mistral Large, embeddings, etc.). |
| [langchain_pinecone](https://pub.dev/packages/langchain_pinecone) | [![langchain_pinecone](https://img.shields.io/pub/v/langchain_pinecone.svg)](https://pub.dev/packages/langchain_pinecone) | Pinecone vector database integration |
| [langchain_chroma](https://pub.dev/packages/langchain_chroma) | [![langchain_chroma](https://img.shields.io/pub/v/langchain_chroma.svg)](https://pub.dev/packages/langchain_chroma) | Chroma vector database integration |
| [langchain_supabase](https://pub.dev/packages/langchain_supabase) | [![langchain_supabase](https://img.shields.io/pub/v/langchain_supabase.svg)](https://pub.dev/packages/langchain_supabase) | Supabase Vector database integration |

Functionality provided by each integration package:

Expand Down
2 changes: 1 addition & 1 deletion packages/langchain_ollama/lib/langchain_ollama.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// LangChain.dart integration module for Ollama (run Llama 2, Mistral, Vicuna and other models locally).
/// LangChain.dart integration module for Ollama (run Llama 3, Mistral, Vicuna and other models locally).
library;

export 'src/chat_models/chat_models.dart';
Expand Down
Loading
Loading