gollm
  • Introduction
  • Getting started
    • Getting started
    • Basic usage
    • Configuration
    • Memory
    • Examples inside Prompts
  • Prompt-template
    • Sumarize
    • Question Answering
    • Chain of Thought
    • Structured Output
  • advanced features
    • Advanced features
    • Prompt engineering
    • Comparison
    • JSON output validation
    • Prompt Optimization
  • Examples
    • Example
    • 1. Basic usage
    • 2. Prompt types
    • 3. Compare providers
    • 4. Custom config
    • 5. Advanced Prompt
    • 6. Structured output
    • 7. Structured output comparison
    • 8. Content creation workflo
    • Ollama Example
    • Prompt Optimizer
    • Batch Prompt Optimizer
  • API reference
  • FAQ
Powered by GitBook
On this page

Was this helpful?

  1. Getting started

Basic usage

Basic Usage of gollm

gollm provides a straightforward way to interact with language models. Here are some basic usage patterns:

Creating an LLM Instance

llm, err := gollm.NewLLM(
	gollm.SetProvider("openai"),
	gollm.SetModel("gpt-4o-mini"),
	gollm.SetAPIKey("your-api-key-here"),
)

Creating a Prompt

prompt := gollm.NewPrompt("Summarize the main points of the given text.",
	gollm.WithContext("The text is about climate change."),
	gollm.WithMaxLength(100),
)

Generating a Response

response, err := llm.Generate(context.Background(), prompt)
if err != nil {
	log.Fatalf("Failed to generate response: %v", err)
}
fmt.Println(response)

These basic patterns will help you get started with gollm. As you become more familiar with the package, you can explore its more advanced features.

PreviousGetting startedNextConfiguration

Last updated 9 months ago

Was this helpful?