0

我的OpenAI库发布了!!!

 1 year ago
source link: https://studygolang.com/articles/36142
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

我的OpenAI库发布了!!!

MonsterMeng92 · 4天之前 · 1012 次点击 · 预计阅读时间 3 分钟 · 大约8小时之前 开始浏览    

chatGPT正式发布已经有段时间了,这段时间我也深度体验了chatGPT的魅力。

OpenAI除了提供网页版的chatGPT,还通过api的形式提供了很多其它服务,包括文字纠错、图片生成、音频转换等等。

作为程序员,即使有现成的openai库,但还是免不了想自己造轮子,所以就有这个openai库

当前这个库刚刚开发完成,还有很多需要优化的地方,所要实现的功能都是OpenAI API提供的,目前已经完成了以下接口的开发:

Engines已经废弃,其功能由Models提供。

在项目的cmd目录下提供了一个简单地http服务,实现了对上面接口的调用。

以下是chatGPT的接口调用的简单示例:

package main

import (
    "context"
    "fmt"
    "os"

    "github.com/mengbin92/openai"
)

func main() {
    client := openai.NewClient("your token", "your org", "proxy")

    resp, err := client.CreateChatCompletion(
        context.Background(),
        &openai.ChatCompletionRequset{
            Model: openai.GPT3Dot5Turbo,
            Messages: []openai.Message{
                {Role: openai.ChatMessageRoleUser, Content: "hi!"},
            },
        },
    )
    if err != nil {
        fmt.Printf("CreateChatCompletion error: %s\n", err.Error())
        os.Exit(-1)
    }
    fmt.Println(resp.Choices[0].Message.Content)
}

孟斯特

声明:本作品采用署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)进行许可,使用时请注明出处。
Author: mengbin
blog: mengbin
Github: mengbin92
cnblogs: 恋水无意



有疑问加站长微信联系(非本文作者))

280

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK