Skip to content

Commit

Permalink
fix(backend): handle colon symbols in model id (#537)
Browse files Browse the repository at this point in the history
Signed-off-by: MICHAEL DESMOND <mdesmond@us.ibm.com>
  • Loading branch information
michael-desmond authored Mar 8, 2025
1 parent e5dd2e3 commit ff8069c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
16 changes: 16 additions & 0 deletions typescript/examples/backend/chatFromName.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import "dotenv/config.js";
import { createConsoleReader } from "examples/helpers/io.js";
import { UserMessage } from "beeai-framework/backend/message";
import { ChatModel } from "beeai-framework/backend/chat";

const llm = await ChatModel.fromName("ollama:granite3.2:8b");

const reader = createConsoleReader();

for await (const { prompt } of reader) {
const response = await llm.create({
messages: [new UserMessage(prompt)],
});
reader.write(`LLM 🤖 (txt) : `, response.getTextContent());
reader.write(`LLM 🤖 (raw) : `, JSON.stringify(response.messages));
}
4 changes: 3 additions & 1 deletion typescript/src/backend/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export function parseModel(name: string) {
if (!name) {
throw new ValueError("Neither 'provider' nor 'provider:model' was specified.");
}
const [providerId, modelId] = name.split(":") as [ProviderName, string];
const [providerId, ...rest] = name.split(":") as [ProviderName, ...string[]];
const modelId = rest.join(":");

const providerDef = findProviderDef(providerId);
if (!providerDef) {
throw new ValueError("Model does not contain provider name!");
Expand Down

0 comments on commit ff8069c

Please sign in to comment.