Skip to content

edgee-cloud/openai-chat-component

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

OpenAI Chat component for Edgee

Coverage Status GitHub issues Edgee Component Registry

This component provides a simple way to integrate the OpenAI Chat API (or other OpenAI-compatible APIs) on Edgee, served directly at the edge. You map the component to a specific endpoint such as /chat, and then you invoke it from your frontend code.

Quick Start

  1. Download the latest component version from our releases page
  2. Place the openai.wasm file in your server (e.g., /var/edgee/components)
  3. Add the following configuration to your edgee.toml:
[[components.edge_functions]]
id = "openai"
file = "/var/edgee/components/openai.wasm"
settings.edgee_path = "/chat"
settings.api_key = "sk-XYZ"
settings.model = "gpt-3.5-turbo"

# optional settings:
settings.max_completion_tokens = "100" # optional, by default it's unlimited
settings.default_system_prompt="You are a funny assistant, always adding a short joke after your response." # optional, no automatic system prompt by default
settings.api_hostname = "api.openai.com" # optional, in case you're using a different OpenAI-compatible API

How to use the HTTP endpoint

You can send requests to the endpoint and show the response message as follows:

const response = await fetch('/chat', {
  method: 'POST',
  body: JSON.stringify({
    messages: [{
        role: 'user',
        content: 'Hello! Please say "ok" if this API call is working.',
    }],
  }),
});
const json = await response.json();
console.log(json.content);

Development

Building from Source

Prerequisites:

Build command:

edgee component build

Test command (with local HTTP emulator):

edgee component test

Test coverage command:

make test.coverage[.html]

Contributing

Interested in contributing? Read our contribution guidelines

Security

Report security vulnerabilities to security@edgee.cloud

About

OpenAI Chat Edgee Component

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published