0.1.1 • Published 8 months ago
@dfinity/llm v0.1.1
@dfinity/llm
A library for making requests to the LLM canister on the Internet Computer.
Install
npm install @dfinity/llmUsage
Prompting (single message)
import { IDL, update } from "azle";
import * as llm from "@dfinity/llm";
export default class {
  @update([IDL.Text], IDL.Text)
  async prompt(prompt: string): Promise<string> {
    return await llm.prompt(llm.Model.Llama3_1_8B, prompt);
  }
}Chatting (multiple messages)
import { IDL, update } from "azle";
import { chat_message as ChatMessageIDL } from "azle/canisters/llm/idl";
import * as llm from "@dfinity/llm";
export default class {
  @update([IDL.Vec(ChatMessageIDL)], IDL.Text)
  async chat(messages: llm.ChatMessage[]): Promise<string> {
    return await llm.chat(llm.Model.Llama3_1_8B, messages);
  }
}