Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ollama use agent and tools error #1045

Open
pdxrlj opened this issue Oct 9, 2024 · 1 comment
Open

ollama use agent and tools error #1045

pdxrlj opened this issue Oct 9, 2024 · 1 comment

Comments

@pdxrlj
Copy link

pdxrlj commented Oct 9, 2024

func main() {
	llm, err := ollama.New(
		ollama.WithModel("qwen2.5:14b"),
		ollama.WithFormat("json"),
		ollama.WithHTTPClient(httpClient),
	)
	if err != nil {
		panic(err)
	}

	content := []llms.MessageContent{
		llms.TextParts(llms.ChatMessageTypeHuman, "What is the weather like in Chicago?"),
	}
	generateContent, err := llm.GenerateContent(context.Background(), content, llms.WithTools(llmTools))
	if err != nil {
		panic(err)
	}
	println(generateContent.Choices[0].Content)

	AgentsTest(llm)
}

func AgentsTest(llm llms.Model) {
	agent := agents.NewOneShotAgent(llm, agentTools, agents.WithMaxIterations(1))
	executor := agents.NewExecutor(agent)
	input := "这段话的中文意思是什么:hello world"
	answer, err := chains.Run(context.Background(), executor, input)
	if err != nil {
		panic(err)
	}
	fmt.Println(answer)
}

var agentTools = []tools.Tool{
	&TranslateTools{},
}

var llmTools = []llms.Tool{
	{
		Type: "function",
		Function: &llms.FunctionDefinition{
			Name:        "getCurrentWeather",
			Description: "Get the current weather in a given location",
			Parameters: map[string]any{
				"type": "object",
				"properties": map[string]any{
					"location": map[string]any{
						"type":        "string",
						"description": "The city and state, e.g. San Francisco, CA",
					},
				},
				"required": []string{"location"},
			},
		},
	},
}

var _ tools.Tool = (*TranslateTools)(nil)

type TranslateTools struct {
}

func (t TranslateTools) Name() string {
	return "translation_content"
}

func (t TranslateTools) Description() string {
	return "翻译用户输入的content从source_language到target_language"
}

func (t TranslateTools) Call(ctx context.Context, input string) (string, error) {
	fmt.Println("input:", input)
	return input, nil
}

response error

{

panic: unable to parse agent output:

goroutine 1 [running]:
main.AgentsTest({0xee41a8?, 0xc0000fec00?})
        D:/code/golang/langchaingo_demo/main.go:60 +0x11f
main.main()
        D:/code/golang/langchaingo_demo/main.go:51 +0x3a5
exit status 2

@pdxrlj
Copy link
Author

pdxrlj commented Oct 9, 2024

Can anyone tell me why?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant