ernie-function-call-example

command module
v0.0.0-...-3308821 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

ERNIE Function Call Example

This example demonstrates how to use the ERNIE (Enhanced Representation through kNowledge IntEgration) language model with function calling capabilities using the LangChain Go library.

What This Example Does

  1. Initializes the ERNIE Model:

    • Sets up the ERNIE model with specific configurations, including the model name and authentication details.
  2. Defines a Weather Function:

    • Implements a getCurrentWeather function that simulates fetching weather data for a given location.
  3. Registers Function Definition:

    • Defines a function that can be called by the ERNIE model, specifying its name, description, and parameters.
  4. Generates Content with Function Call:

    • Sends a query about the weather in Boston to the ERNIE model.
    • The model is provided with the capability to call the getCurrentWeather function if needed.
  5. Handles the Response:

    • Checks if the model's response includes a function call.
    • If a function call is present, it prints the details of the call.

Key Features

  • ERNIE Model Integration: Demonstrates how to initialize and use the ERNIE model in a Go application.
  • Function Calling: Shows how to define and use custom functions that can be called by the language model.
  • Error Handling: Includes basic error handling for model initialization and content generation.

Usage Notes

  • You need to replace the placeholder values for ak, sk, and accesstoken with your actual ERNIE API credentials.
  • This example is designed to showcase the function calling feature. In a real-world scenario, you would implement actual weather data fetching logic in the getCurrentWeather function.

Running the Example

To run this example, ensure you have the necessary dependencies installed and your ERNIE API credentials set up. Then, execute the Go file to see the model's response and any potential function calls it makes.

This example provides a great starting point for developers looking to integrate ERNIE's language capabilities with custom function calling in their Go applications.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL