-
-
Notifications
You must be signed in to change notification settings - Fork 607
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'llms/fake' of github.com:devalexandre/langchaingo into …
…llms/fake
- Loading branch information
Showing
206 changed files
with
3,951 additions
and
598 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ func textToSplit() []schema.Document { | |
|
||
log.Println("Document loaded: ", len(docs)) | ||
} | ||
``` | ||
<DocCardList /> | ||
89 changes: 89 additions & 0 deletions
89
docs/docs/modules/model_io/models/llms/Integrations/groq.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
--- | ||
sidebar_label: Groq | ||
--- | ||
|
||
# Groq | ||
|
||
## Overview | ||
|
||
This documentation provides a detailed overview and technical guidance for integrating Groq's machine learning models with the Langchaingo library in the Go programming environment. This integration allows Go developers to leverage the power of pre-trained AI models for various applications, including natural language processing, text generation, and more. | ||
|
||
## Prerequisites | ||
|
||
- Go programming language installed on your machine (version 1.22.0 or higher recommended). | ||
- A valid Groq API key. Obtain it by creating an account on the Groq platform and generating a new token. | ||
|
||
## Installation | ||
|
||
To install the Groq package in your Go project, run the following command: | ||
|
||
```bash | ||
go get github.com/tmc/langchaingo | ||
``` | ||
|
||
Ensure that your Groq API key is set as an environment variable: | ||
|
||
```bash | ||
export GROQ_API_KEY=your-api-key | ||
``` | ||
|
||
You can use .env file to store the API key and load it in your Go application. | ||
|
||
.env file: | ||
|
||
```bash | ||
GROQ_API_KEY=your-api-key | ||
``` | ||
but you not need use godotenv package to load the .env file. | ||
|
||
|
||
## Usage | ||
|
||
```go | ||
package main | ||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"os" | ||
"github.com/joho/godotenv" | ||
"github.com/tmc/langchaingo/llms" | ||
"github.com/tmc/langchaingo/llms/openai" | ||
) | ||
func main() { | ||
// Load the Groq API key from the .env file if you use it | ||
err := godotenv.Load() | ||
if err != nil { | ||
log.Fatalf("Error loading .env file") | ||
} | ||
apiKey := os.Getenv("GROQ_API_KEY") | ||
llm, err := openai.New( | ||
openai.WithModel("llama3-8b-8192"), | ||
openai.WithBaseURL("https://api.groq.com/openai/v1"), | ||
openai.WithToken(apiKey), | ||
) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
ctx := context.Background() | ||
_, err = llms.GenerateFromSinglePrompt(ctx, | ||
llm, | ||
"Write a long poem about how golang is a fantastic language.", | ||
llms.WithTemperature(0.8), | ||
llms.WithMaxTokens(4096), | ||
llms.WithStreamingFunc(func(ctx context.Context, chunk []byte) error { | ||
fmt.Print(string(chunk)) | ||
return nil | ||
}), | ||
) | ||
fmt.Println() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,46 @@ | ||
# 🎉 Examples | ||
# LangChain Go Examples 🚀 | ||
|
||
This directory tree contains examples that are independently buildable and runnable. | ||
Welcome to the exciting set of LangChain Go examples! 🎉 This directory tree is packed with fun and practical demonstrations of how to use LangChain with various language models and tools. Whether you're a seasoned AI developer or just starting out, there's something here for everyone! | ||
|
||
## What's Inside? 📦 | ||
|
||
This collection includes examples for: | ||
|
||
- Different Language Models: OpenAI, Anthropic, Cohere, Ollama, and more! | ||
- Vector Stores: Chroma, Pinecone, Weaviate, and others for efficient similarity searches. | ||
- Chains and Agents: See how to build complex AI workflows and autonomous agents. | ||
- Tools and Integrations: Explore connections with Zapier, SQL databases, and more. | ||
- Memory Systems: Learn about various memory implementations for contextual conversations. | ||
|
||
## Key Features 🌟 | ||
|
||
1. **Diverse LLM Integration**: Examples showcasing integration with multiple language models. | ||
2. **Vector Store Demonstrations**: Practical uses of vector databases for semantic search and data retrieval. | ||
3. **Chain and Agent Construction**: Learn to build sophisticated AI workflows and autonomous agents. | ||
4. **Tool Usage**: See how to leverage external tools and APIs within your AI applications. | ||
5. **Memory Management**: Explore different ways to maintain context in conversations. | ||
|
||
## How to Use 🛠️ | ||
|
||
Each example is contained in its own directory with a dedicated README and Go files. To run an example: | ||
|
||
1. Navigate to the example's directory. | ||
2. Read the README for specific instructions and requirements. | ||
3. Run the Go file(s) as instructed. | ||
|
||
## Getting Started 🚀 | ||
|
||
1. Clone this repository. | ||
2. Ensure you have Go installed on your system. | ||
3. Set up any required API keys or environment variables as specified in individual examples. | ||
4. Dive into the example that interests you most! | ||
|
||
## Contribute 🤝 | ||
|
||
Feel free to contribute your own examples or improvements! We love seeing creative uses of LangChain Go. | ||
|
||
## Have Fun! 😄 | ||
|
||
Remember, the world of AI is vast and exciting. These examples are just the beginning. Feel free to experiment, modify, and build upon these examples to create your own amazing AI applications! | ||
|
||
Happy coding, and may your AI adventures be ever thrilling! 🚀🤖 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Anthropic Completion Example | ||
|
||
Hello there, fellow Go enthusiasts and AI adventurers! 👋 Welcome to this exciting example of using the Anthropic API with Go! | ||
|
||
## What's in this directory? | ||
|
||
This directory contains a simple yet powerful example of how to use the Anthropic API to generate text completions using Go. Here's what you'll find: | ||
|
||
1. `anthropic_completion_example.go`: This is the main Go file that demonstrates how to use the Anthropic API. It's a great starting point for your AI-powered adventures! | ||
|
||
## What does the code do? | ||
|
||
The `anthropic_completion_example.go` file showcases how to: | ||
|
||
- Initialize an Anthropic LLM (Language Model) client | ||
- Generate text completions using the Claude 3 Opus model | ||
- Stream the generated text in real-time | ||
|
||
It even includes a fun prompt asking Claude to write a poem about Golang-powered AI systems! 🤖📝 | ||
|
||
## How to use this example | ||
|
||
1. Make sure you have Go installed on your system. | ||
2. Set up your Anthropic API key as an environment variable. | ||
3. Run the example using `go run anthropic_completion_example.go`. | ||
4. Watch as the AI-generated poem streams to your console! | ||
|
||
## Dependencies | ||
|
||
This project uses the fantastic `langchaingo` library to interact with the Anthropic API. It's a great tool for building AI-powered applications in Go! | ||
|
||
## What to expect | ||
|
||
When you run the example, you'll see a poem about Golang-powered AI systems being generated and printed to your console in real-time. It's like watching an AI poet at work! 🎭 | ||
|
||
## Have fun! | ||
|
||
We hope this example inspires you to create amazing AI-powered applications using Go and Anthropic's powerful language models. Happy coding! 🚀🎉 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Anthropic Tool Call Example 🌟 | ||
|
||
Welcome to the Anthropic Tool Call Example! This fun little Go program demonstrates how to use the Anthropic API to create an AI assistant that can answer questions about the weather using function calling. Let's dive in and see what it does! | ||
|
||
## What Does This Example Do? 🤔 | ||
|
||
This example showcases the following cool features: | ||
|
||
1. **AI-Powered Weather Assistant**: It creates an AI assistant using Anthropic's Claude model that can answer questions about the weather in different cities. | ||
|
||
2. **Function Calling**: The assistant can use a special tool (function) called `getCurrentWeather` to fetch weather information for specific locations. | ||
|
||
3. **Conversation Flow**: It demonstrates a back-and-forth conversation between a human and the AI assistant, including multiple queries about weather in different cities. | ||
|
||
4. **Tool Execution**: When the AI assistant needs to use the weather tool, the program executes it and provides the results back to the assistant. | ||
|
||
## How It Works 🛠️ | ||
|
||
1. The program starts by creating an Anthropic client using the Claude 3 Haiku model. | ||
|
||
2. It then initiates a conversation by asking about the weather in Boston. | ||
|
||
3. The AI assistant recognizes the need for weather information and calls the `getCurrentWeather` function. | ||
|
||
4. The program executes the function call, fetching mock weather data for Boston. | ||
|
||
5. The AI assistant receives the weather data and formulates a response. | ||
|
||
6. The conversation continues with additional questions about weather in Chicago, demonstrating the assistant's ability to handle multiple queries and retain context. | ||
|
||
## Fun Features 🎉 | ||
|
||
- **Mock Weather Data**: The example uses a simple map to provide mock weather data for Boston and Chicago. It's not real-time data, but it's perfect for demonstrating how the system works! | ||
|
||
- **Flexible Conversations**: You can easily modify the conversation flow by adding more questions or changing the cities mentioned. | ||
|
||
- **Tool Definition**: The `availableTools` slice defines the `getCurrentWeather` function, which the AI can use to fetch weather information. | ||
|
||
## Try It Out! 🚀 | ||
|
||
Run the example and watch as the AI assistant cheerfully answers questions about the weather in different cities. Feel free to modify the code to add more cities or even create your own tools for the AI to use! | ||
|
||
Happy coding, and may your weather always be sunny! ☀️ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.