From 92b017d0e1f20d40a8e5c82a7643f6db89d0220d Mon Sep 17 00:00:00 2001 From: Zheng Kai Date: Fri, 31 Mar 2023 16:44:36 +0800 Subject: [PATCH] up --- misc/test/curl.sh | 4 ++-- proto/rsp.proto | 1 + server/src/core/pool.go | 3 ++- server/src/core/req.go | 2 +- server/src/util/file.go | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/misc/test/curl.sh b/misc/test/curl.sh index ba3194b..a55c2fd 100755 --- a/misc/test/curl.sh +++ b/misc/test/curl.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash -ex API_HOST="http://10.0.84.49:22035" # API_HOST="http://localhost:22035" @@ -6,4 +6,4 @@ API_HOST="http://10.0.84.49:22035" curl "${API_HOST}/v1/engines/text-embedding-ada-002/embeddings" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $OPENAI_API_KEY" \ - -d '{"input":[ "\u80fd\u91cf\u793c\u7269\u662f\u600e\u4e48\u56de\u4e8b\uff1f\u7528\u4e2d\u6587"], "encoding_format": "base64"}' + -d '{"input":[ "\u80fd\u91cf\u793c\u7269\u662f\u600e\u4e48\u56de\u4e8b\uff1f\u7528\u4e2d\u6587"], "encoding_format": "base64"}' diff --git a/proto/rsp.proto b/proto/rsp.proto index 5793b89..867bed4 100644 --- a/proto/rsp.proto +++ b/proto/rsp.proto @@ -13,4 +13,5 @@ message Rsp { message RspUsage { uint32 prompt_tokens = 1; uint32 total_tokens = 2; + uint32 completion_tokens = 3; } diff --git a/server/src/core/pool.go b/server/src/core/pool.go index 9d161c6..584a3c9 100644 --- a/server/src/core/pool.go +++ b/server/src/core/pool.go @@ -7,7 +7,7 @@ import ( "time" ) -func (c *Core) add(req *pb.Req, hr *http.Request) (pr *row) { +func (c *Core) add(req *pb.Req, hr *http.Request) (pr *row, cached bool) { hash := req.Hash() @@ -16,6 +16,7 @@ func (c *Core) add(req *pb.Req, hr *http.Request) (pr *row) { if ok { zj.F(`hit %x`, hash) c.mux.Unlock() + cached = true return } diff --git a/server/src/core/req.go b/server/src/core/req.go index b1b0281..f1d3ff1 100644 --- a/server/src/core/req.go +++ b/server/src/core/req.go @@ -15,7 +15,7 @@ func (c *Core) getAB(p *pb.Req, r *http.Request) (ab []byte, cached bool, err er return } - pr := c.add(p, r) + pr, cached := c.add(p, r) go func() { reqFile := util.CacheName(p.Hash()) + `-req.json` diff --git a/server/src/util/file.go b/server/src/util/file.go index 848ef8f..33e0945 100644 --- a/server/src/util/file.go +++ b/server/src/util/file.go @@ -18,7 +18,7 @@ type DownloadFunc func(url string) (ab []byte, err error) // CacheName ... func CacheName(hash [16]byte) string { - s := fmt.Sprintf(`cache/%x/%x/%x`, hash[0:2], hash[2:4], hash[4:]) + s := fmt.Sprintf(`cache/%02x/%02x/%02x/%x`, hash[0], hash[1], hash[2], hash[3:]) os.MkdirAll(StaticFile(filepath.Dir(s)), 0755) return s }