当前位置: 首页 > news >正文

如何做好网站针对搜索引擎的seo室内设计项目概况

如何做好网站针对搜索引擎的seo,室内设计项目概况,华为企业官网首页,灰色项目网站代做目录 1.deepseek官方API调用文档1.访问格式2.curl组装 2.go代码1. config 配置2.模型相关3.错误处理4.deepseekAPI接口实现5. 调用使用 3.响应实例 1.deepseek官方API调用文档 1.访问格式 现在我们来解析这个curl 2.curl组装 // 这是请求头要加的参数-H Content-Type:… 目录 1.deepseek官方API调用文档1.访问格式2.curl组装 2.go代码1. config 配置2.模型相关3.错误处理4.deepseekAPI接口实现5. 调用使用 3.响应实例 1.deepseek官方API调用文档 1.访问格式 现在我们来解析这个curl 2.curl组装 // 这是请求头要加的参数-H Content-Type: application/json \-H Authorization: Bearer DeepSeek API Key \// 这是请求体要加的参数 -d {model: deepseek-chat,messages: [{role: system, content: You are a helpful assistant.},{role: user, content: Hello!}],stream: false}这个里面可以看出user角色使我们要输入的问题stream选择是否为流式响应 2.go代码 1. config 配置 type Config struct {BaseURL stringAPIKey stringHTTPClient *http.Client }2.模型相关 type Model interface {Chat(ctx context.Context, req Request) (*Response, error)Stream(ctx context.Context, req Request) (-chan Response, error) }type Request struct {Model string json:modelMessages []Message json:messagesStream bool json:stream }type Message struct {Role string json:roleContent string json:content }type Response struct {Content string json:content }3.错误处理 // Error 标准错误类型 type Error struct {Code intMessage stringModel string }func (e *Error) Error() string {return fmt.Sprintf([%s] %d: %s, e.Model, e.Code, e.Message) }4.deepseekAPI接口实现 type DeepSeek struct {Cfg ai.Config }func NewDeepSeek(cfg ai.Config) *DeepSeek {return DeepSeek{Cfg: cfg} }func (d *DeepSeek) Stream(ctx context.Context, request ai.Request) (-chan ai.Response, error) {return d.handleStreaming(ctx, request) }func (d *DeepSeek) Chat(ctx context.Context, request ai.Request) (*ai.Response, error) {doRequest, err : d.doRequest(ctx, request, false)if err ! nil {return nil, err}return d.parseResponse(doRequest) }func (d *DeepSeek) parseResponse(resp *http.Response) (*ai.Response, error) {all, err : io.ReadAll(resp.Body)if err ! nil {return nil, fmt.Errorf(io.ReadAll failed, err: %v\n, err)}defer resp.Body.Close()return ai.Response{Content: string(all)}, nil }// 私有方法 func (d *DeepSeek) doRequest(ctx context.Context, req ai.Request, stream bool) (*http.Response, error) {req.Stream streambody, _ : json.Marshal(req)httpReq, err : http.NewRequestWithContext(ctx,POST,d.Cfg.BaseURL/chat/completions,bytes.NewReader(body),)// 设置请求头httpReq.Header.Set(Content-Type, application/json)httpReq.Header.Set(Authorization, Bearer apiKey)resp, err : d.Cfg.HTTPClient.Do(httpReq)if err ! nil {return nil, ai.Error{Model: deepseek,Code: http.StatusInternalServerError,Message: fmt.Sprintf(HTTP error: %v, err),}}if resp.StatusCode ! http.StatusOK {return nil, ai.Error{Model: deepseek,Code: http.StatusInternalServerError,Message: fmt.Sprintf(failed to request: %v, err),}}return resp, nil }func (d *DeepSeek) handleStreaming(ctx context.Context, req ai.Request) (-chan ai.Response, error) {ch : make(chan ai.Response)go func() {defer close(ch)// 发起流式请求resp, err : d.doRequest(ctx, req, true)if err ! nil {ch - ai.Response{Content: request error!}return}defer resp.Body.Close()scanner : bufio.NewScanner(resp.Body)for scanner.Scan() {select {case -ctx.Done():ch - ai.Response{Content: ctx done!}returndefault:// 解析事件流event : parseEvent(scanner.Bytes())if event ! nil {ch - *event}}}}()return ch, nil }func parseEvent(line []byte) *ai.Response {// 处理事件流格式if !bytes.HasPrefix(line, []byte(data: )) {return nil}payload : bytes.TrimPrefix(line, []byte(data: ))if string(payload) [DONE] {return nil}// 解析响应结构var chunk struct {Choices []struct {Delta struct {Content string json:content}FinishReason string json:finish_reason}}if err : json.Unmarshal(payload, chunk); err ! nil {return nil}if len(chunk.Choices) 0 {content : chunk.Choices[0].Delta.ContentfinishReason : chunk.Choices[0].FinishReasonif content ! {return ai.Response{Content: content}}if finishReason stop {return nil}}return nil } 5. 调用使用 func main() {cfg : ai.Config{BaseURL: https://api.deepseek.com/,APIKey: key,HTTPClient: http.Client{},}// 初始化deepseekd : deepseek.NewDeepSeek(cfg)// 封装请求体body : ai.Request{Model: deepseek-chat,Messages: []ai.Message{{Role: system, Content: You are a helpful assistant.}, {Role: user, Content: 你是谁}},}// 同步调用chat, err : d.Chat(context.Background(), body)if err ! nil {panic(err)}fmt.Println(chat.Content)// 流式调用stream, _ : d.Stream(context.Background(), body)for chunk : range stream {fmt.Printf(chunk.Content)} } 3.响应实例 // 同步 {id:,object:chat.completion,created:,model:deepseek-chat,choices:[{index:0,message:{role:assistant,content:您好我是由中国的深度求索DeepSeek公司开发的何任何问题我会尽我所能为您提供帮助。},logprobs:null,finish_reason:stop}],usage:{prompt_tokens:10,completion_tokens:37,total_tokens:47,prompt_tokens_details:{cached_tokens:0},prompt_cache_hit_tokens:0,proms:10},system_fingerprint:fp_3a5770e1b4}// 流式 您好我是由中国的深度求索DeepSeek公司开发的智能助手DeepSeek-V3。如您有任何任何问题我会尽我所能为您提供帮助。 代码地址https://gitee.com/li-zhuoxuan/go_ai
http://www.ho-use.cn/article/10823334.html

相关文章:

  • 网站制作报价单模板做网站哪种字体好看
  • 南山区网站建设房地产的未来趋势分析
  • 学校网站建设方案策划书网站主页和子页风格如何统一
  • 郑州市房产信息网官方网站米课中有个内贸网站建设
  • 电影网站膜拜云尚网站建设
  • 做一个简单的网站需要多少钱免费申请试用网站
  • 云南省建设厅官方网站证书wordpress小说网站模板下载
  • 校本教研网站建设进口博览会2022
  • 专业设计网站的公司视频网站开发流程图
  • 网站开发小程序开发公司潍坊建设网站的公司电话
  • 微网站免费创建平台闵行区做网站
  • 网站站内关键词优化杭州网站建设就找蓝韵网络
  • 站长工具使用彩票网站建设 极云
  • 浅谈网站开发的意义抚州市建设局网站查询
  • 申请做网站_论坛版主wordpress注册显示密码错误
  • 建设银行园区公积金管理中心网站wordpress千万数据优化
  • 宣传类的网站怎么做wordpress有多强大
  • y2学年做的租房网站青岛海西建设集团官方网站
  • 网站建设费做什么wordpress 会员分类
  • 厦门专业网站可以做婚礼鲜花布置的网站
  • 南京市城乡建设局网站国网电子商务平台官网
  • 酒店预定类网站建设制作音乐app
  • 引蜘蛛网站建筑工程包括哪些项目
  • 惠州网站建设 熊掌号免费代理网页
  • 响应式网站如何做的北京网站优化培训
  • 网站建设落后发言WordPress记录访问者ip
  • 宁德营销型网站建设新加坡室内设计公司排名
  • 莆田网站建设网yy直播下载电脑版
  • 网上做设计的网站有哪些常州新北区网站建设
  • Wordpress网站能做seo吗互通登录插件WordPress