@@ -4,9 +4,14 @@ import { serve } from "https://deno.land/std@0.181.0/http/server.ts";
4
4
const resourceName :string = "your-resource-name" ;
5
5
6
6
// The deployment name you chose when you deployed the model.
7
- const deployName :string = "deployment-name" ;
7
+ // const deployName:string = "deployment-name";
8
8
9
9
const apiVersion :string = "2023-03-15-preview" ;
10
+ // 自定义 mapper 来映射 model 字段
11
+ const mapper :any = {
12
+ 'gpt-3.5-turbo' : 'gpt35'
13
+ // 其他映射规则可以在这里添加
14
+ } ;
10
15
11
16
async function handleRequest ( request :Request ) :Promise < Response > {
12
17
if ( request . method === 'OPTIONS' ) {
@@ -24,12 +29,25 @@ async function handleRequest(request:Request):Promise<Response> {
24
29
} else {
25
30
return new Response ( '404 Not Found' , { status : 404 } )
26
31
}
27
-
28
- const fetchAPI :string = `https://${ resourceName } .openai.azure.com/openai/deployments/${ deployName } /${ path } ?api-version=${ apiVersion } ` ;
32
+
33
+
34
+ // 获取 model 字段的值,并进行映射
35
+ let deployName :string = '' ;
29
36
let body :any ;
30
37
if ( request . method === 'POST' ) {
31
38
body = await request . json ( ) ;
39
+ const modelName :string | undefined = body ?. model ;
40
+ if ( modelName ) {
41
+ deployName = mapper [ modelName ] || modelName ;
42
+ }
32
43
}
44
+
45
+ const fetchAPI :string = `https://${ resourceName } .openai.azure.com/openai/deployments/${ deployName } /${ path } ?api-version=${ apiVersion } ` ;
46
+
47
+ // let body:any;
48
+ // if (request.method === 'POST') {
49
+ // body = await request.json();
50
+ // }
33
51
const authKey :string | null = request . headers . get ( 'Authorization' ) ;
34
52
if ( ! authKey ) {
35
53
return new Response ( "Not allowed" , { status : 403 } ) ;
@@ -55,6 +73,7 @@ async function handleRequest(request:Request):Promise<Response> {
55
73
56
74
}
57
75
76
+
58
77
function sleep ( ms :number ) :Promise < void > {
59
78
return new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
60
79
}
0 commit comments