Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support yi ai model #980

Merged
merged 2 commits into from
May 21, 2024
Merged

feat: support yi ai model #980

merged 2 commits into from
May 21, 2024

Conversation

Chi-Kai
Copy link
Contributor

@Chi-Kai Chi-Kai commented May 20, 2024

Ⅰ. Describe what this PR did

Support Yi ai model, api documentation(https://platform.lingyiwanwu.com)

Ⅱ. Does this pull request fix one issue?

fixes #957

Ⅲ. Why don't you add test cases (unit test/integration test)?

Ⅳ. Describe how to verify it

envoy.yaml:

admin:
  address:
    socket_address:
      protocol: TCP
      address: 0.0.0.0
      port_value: 9901
static_resources:
  listeners:
    - name: listener_0
      address:
        socket_address:
          protocol: TCP
          address: 0.0.0.0
          port_value: 10000
      filter_chains:
        - filters:
            - name: envoy.filters.network.http_connection_manager
              typed_config:
                "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
                scheme_header_transformation:
                  scheme_to_overwrite: https
                stat_prefix: ingress_http
                # Output envoy logs to stdout
                access_log:
                  - name: envoy.access_loggers.stdout
                    typed_config:
                      "@type": type.googleapis.com/envoy.extensions.access_loggers.stream.v3.StdoutAccessLog
                # Modify as required
                route_config:
                  name: local_route
                  virtual_hosts:
                    - name: local_service
                      domains: [ "*" ]
                      routes:
                        - match:
                            prefix: "/"
                          route:
                            cluster: yi
                            timeout: 300s
                http_filters:
                  - name: wasmtest
                    typed_config:
                      "@type": type.googleapis.com/udpa.type.v1.TypedStruct
                      type_url: type.googleapis.com/envoy.extensions.filters.http.wasm.v3.Wasm
                      value:
                        config:
                          name: wasmtest
                          vm_config:
                            runtime: envoy.wasm.runtime.v8
                            code:
                              local:
                                filename: /etc/envoy/plugin.wasm
                          configuration:
                            "@type": "type.googleapis.com/google.protobuf.StringValue"
                            value: |
                              {
                                "provider": {
                                  "type": "yi",
                                  "apiTokens": [
                                    "your-apiTokens"
                                  ]
                                }
                              }
                  - name: envoy.filters.http.router
  clusters:
    - name: httpbin
      connect_timeout: 30s
      type: LOGICAL_DNS
      # Comment out the following line to test on v6 networks
      dns_lookup_family: V4_ONLY
      lb_policy: ROUND_ROBIN
      load_assignment:
        cluster_name: httpbin
        endpoints:
          - lb_endpoints:
              - endpoint:
                  address:
                    socket_address:
                      address: httpbin
                      port_value: 80
    - name: yi
      connect_timeout: 30s
      type: LOGICAL_DNS
      dns_lookup_family: V4_ONLY
      lb_policy: ROUND_ROBIN
      load_assignment:
        cluster_name: yi
        endpoints:
          - lb_endpoints:
              - endpoint:
                  address:
                    socket_address:
                      address: api.lingyiwanwu.com
                      port_value: 443
      transport_socket:
        name: envoy.transport_sockets.tls
        typed_config:
          "@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
          "sni": "api.lingyiwanwu.com"

Request:

curl "http://localhost:10000/v1/chat/completions"  -H "Content-Type: application/json" -d '{
  "model": "yi-large",            
  "messages": [                                                     
    {                        
      "role": "user",                
      "content": "你好,你是谁?"
    }                                                                                 
  ]                                                 
}'

Response:

{
    "id": "cmpl-1cef946a",
    "object": "chat.completion",
    "created": 12063916,
    "model": "yi-large",
    "usage": {
        "completion_tokens": 42,
        "prompt_tokens": 15,
        "total_tokens": 57
    },
    "choices": [
        {
            "index": 0,
            "message": {
                "role": "assistant",
                "content": "你好!我是一个人工智能助手,专门设计来回答问题、提供信息和帮助解决问题。人们通常叫我“AI助手”或者类似的名字。如果你有任何问题或需要帮助,请随时告诉我!"
            },
            "finish_reason": "stop"
        }
    ]
}

Ⅴ. Special notes for reviews

@CLAassistant
Copy link

CLAassistant commented May 20, 2024

CLA assistant check
All committers have signed the CLA.

@johnlanni johnlanni requested a review from CH3CHO May 20, 2024 09:22
@johnlanni
Copy link
Collaborator

cc @CH3CHO

Copy link
Collaborator

@CH3CHO CH3CHO left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks.

@CH3CHO CH3CHO merged commit 33013d0 into alibaba:main May 21, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AI 代理 Wasm 插件对接零一万物
4 participants