JSON Mode Example
Hello there! ๐ Welcome to this exciting JSON Mode example using the LangChain Go library!
What does this example do?
This nifty little program demonstrates how to use different language model backends to generate responses in JSON format. It's a great way to see how you can get structured data from various AI models!
Here's what it does in a nutshell:
- It sets up a command-line flag to choose which AI backend you want to use.
- It initializes the chosen AI backend (OpenAI, Ollama, Anthropic, or Google AI).
- It sends a prompt asking "Who was the first man to walk on the moon?" and requests the response in JSON format.
- It prints out the JSON response from the AI model.
Cool features:
- ๐ Supports multiple AI backends (OpenAI, Ollama, Anthropic, Google AI)
- ๐ก๏ธ Sets the temperature to 0 for more deterministic responses
- ๐ง Uses JSON mode for structured output
- ๐ Easy to run and experiment with!
How to run:
- Make sure you have the necessary API keys set up for the backend you want to use.
- Run the program with the desired backend flag:
go run json_mode_example.go -backend=openai
Replace openai
with ollama
, anthropic
, or googleai
to try different backends!
Have fun!
This example is a great starting point for exploring how to get structured data from AI models. Feel free to modify the prompt or try different settings to see how the responses change. Happy coding! ๐