form_back.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package compapi
  2. //
  3. //import (
  4. // "time"
  5. // "wechat-api/internal/types"
  6. //
  7. // "github.com/openai/openai-go"
  8. //)
  9. //
  10. //type FormClient struct {
  11. // StdClient
  12. //}
  13. //
  14. //// Generate the JSON schema at initialization time
  15. //var FormResponseSchema = GenerateSchema[FormList]()
  16. //
  17. //type FormResponse struct {
  18. // DataIndex string `json:"dataIndex" jsonschema_description:"表单 id"`
  19. // Value []string `json:"value" jsonschema_description:" 值列表"`
  20. //}
  21. //
  22. //type FormList struct {
  23. // Values []FormResponse `json:"values" jsonschema_description:"表单列表"`
  24. //}
  25. //
  26. ///*
  27. //
  28. //"response_format":{"type":"json_object"}}
  29. //
  30. //{"type":"json_schema",
  31. // "json_schema":{
  32. // "description":"从通话记录中提取表单","name":"keyword_schema","schema":{
  33. // "$schema":"https://json-schema.org/draft/2020-12/schema","additionalProperties":false,"properties":{
  34. // "keywords":{
  35. // "description":"关键词库","items":{"type":"string"},"type":"array"},"regular":{"description":"正则表达式","items":{"type":"string"},"type":"array"},"similar_reply":{"description":"类似回复","items":{"type":"string"},"type":"array"},"swear_words":{"description":"脏话列表","items":{"type":"string"},"type":"array"},"user_intent":{"description":"用户意图","type":"string"},"user_mood":{"description":"用户情绪","type":"string"}},"required":["user_intent","similar_reply","keywords","regular","user_mood","swear_words"],"type":"object"},"strict":true}}
  36. //*/
  37. //
  38. //func (me *FormClient) BuildRequest(req *types.CompApiReq) error {
  39. // nowTime := time.Now().Format("2006-01-02 15:04:05")
  40. // weekday := time.Now().Weekday().String()
  41. // //bytes, err := json.Marshal(req.Variables["form_data"])
  42. // //if err != nil {
  43. // // return err
  44. // //}
  45. // //form_data := string(bytes)
  46. //
  47. // //先重构message
  48. // newMessSlice := make([]types.StdCompMessage, 2)
  49. // newMessSlice[0] = types.StdCompMessage{Role: "system", Content: `# 任务
  50. //请帮助user从聊天记录中提取表单值,并返回一个JSON格式的表单值。
  51. //
  52. //# 背景信息
  53. //当前时间是:` + nowTime + `
  54. //当前星期是:` + weekday + `
  55. //
  56. //# 返回值示例
  57. //* 如表单类型为 input、autoComplete、textarea,返回示例:["表单值"]
  58. //* 如表单类型为 radio、select,返回示例:["值1"]
  59. //* 如表单类型为 checkbox,返回示例:["值1", "值2"]
  60. //* 如表单类型为 cascader,返回示例:["一级值1", "二级值3"]
  61. //* 如表单类型为 date,返回示例:["2025-01-01"]
  62. //* 如没有找到某个表单相关的值,请不要返回该表单`}
  63. //
  64. // newMessSlice[1] = types.StdCompMessage{Role: "user", Content: `# 待提取表单
  65. //` + req.Variables["form_data"] + `
  66. //
  67. //# 聊天记录
  68. //` + req.Variables["chat_history"]}
  69. //
  70. // //再构造ResponseFormat
  71. // if !IsOpenaiModel(req.Model) {
  72. // newMessSlice[1].Content = newMessSlice[1].Content.(string) + `
  73. //# 请以下方的json结构输出
  74. //[{
  75. // "dataIndex": str, # 表单ID
  76. // "value": list[str] # 表单值列表
  77. //}]`
  78. // req.ResponseFormat = openai.ResponseFormatJSONObjectParam{Type: "json_object"}
  79. // } else {
  80. // schemaParam := openai.ResponseFormatJSONSchemaJSONSchemaParam{
  81. // Name: "keyword_schema",
  82. // Description: openai.String("从通话记录中提取表单"),
  83. // Schema: FormResponseSchema,
  84. // Strict: openai.Bool(true),
  85. // }
  86. // req.ResponseFormat = openai.ResponseFormatJSONSchemaParam{JSONSchema: schemaParam}
  87. // }
  88. // //req.Model = oldModel
  89. // req.Messages = newMessSlice
  90. //
  91. // return nil
  92. //}