Skip to content

Commit db2b5a4

Browse files
step 7: configure ollama and use it
1 parent 56d266d commit db2b5a4

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

live-code/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,37 @@ Just add the streamed flag to the request and change the way to display the cont
172172
return Command::SUCCESS;
173173
}
174174
```
175+
176+
## Step 7: Configure Ollama Adapter and use it
177+
178+
Add the Ollama adapter to the configuration:
179+
180+
```yaml
181+
modelflow_ai:
182+
providers:
183+
openai:
184+
enabled: true
185+
credentials:
186+
api_key: '%env(OPENAI_API_KEY)%'
187+
ollama:
188+
enabled: true
189+
190+
adapters:
191+
gpt4o:
192+
enabled: true
193+
llama3_2:
194+
enabled: true
195+
```
196+
197+
Use the Ollama adapter in the command:
198+
199+
```php
200+
/** @var AIChatResponseStream $response */
201+
$response = $this->chatRequestHandler
202+
->createRequest(...$messages)
203+
->addUserMessage($question)
204+
->addCriteria(ModelCriteria::LLAMA3_2)
205+
->streamed()
206+
->build()
207+
->execute();
208+
```

live-code/config/packages/modelflow_ai.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ modelflow_ai:
44
enabled: true
55
credentials:
66
api_key: '%env(OPENAI_API_KEY)%'
7+
ollama:
8+
enabled: true
79

810
adapters:
911
gpt4o:
1012
enabled: true
13+
llama3_2:
14+
enabled: true

live-code/src/Command/ChatCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use ModelflowAi\Chat\Request\Message\AIChatMessage;
77
use ModelflowAi\Chat\Request\Message\AIChatMessageRoleEnum;
88
use ModelflowAi\Chat\Response\AIChatResponseStream;
9+
use ModelflowAi\Integration\Symfony\Criteria\ModelCriteria;
910
use Symfony\Component\Console\Attribute\AsCommand;
1011
use Symfony\Component\Console\Command\Command;
1112
use Symfony\Component\Console\Input\InputArgument;
@@ -50,6 +51,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5051
$response = $this->chatRequestHandler
5152
->createRequest(...$messages)
5253
->addUserMessage($question)
54+
->addCriteria(ModelCriteria::LLAMA3_2)
5355
->streamed()
5456
->build()
5557
->execute();

0 commit comments

Comments
 (0)