shitty quick fix for tavern+openai not working properly

This commit is contained in:
nai-degen 2023-05-29 13:23:38 -05:00
parent f102f02a65
commit 30bdc7cd5e
2 changed files with 10 additions and 4 deletions

View File

@ -1,10 +1,17 @@
import { Key, keyPool } from "../../../key-management"; import { Key, keyPool } from "../../../key-management";
import type { ExpressHttpProxyReqCallback } from "."; import { ExpressHttpProxyReqCallback, isCompletionRequest } from ".";
/** Add a key that can service this request to the request object. */ /** Add a key that can service this request to the request object. */
export const addKey: ExpressHttpProxyReqCallback = (proxyReq, req) => { export const addKey: ExpressHttpProxyReqCallback = (proxyReq, req) => {
let assignedKey: Key; let assignedKey: Key;
if (!isCompletionRequest(req)) {
// Horrible, horrible hack to stop the proxy from complaining about clients
// not sending a model when they are requesting the list of models (which
// requires a key, but obviously not a model).
req.body.model = "gpt-3.5-turbo";
}
if (!req.body?.model) { if (!req.body?.model) {
throw new Error("You must specify a model with your request."); throw new Error("You must specify a model with your request.");
} }

View File

@ -1,6 +1,6 @@
import { Request } from "express"; import { Request } from "express";
import { z } from "zod"; import { z } from "zod";
import type { ExpressHttpProxyReqCallback } from "."; import { ExpressHttpProxyReqCallback, isCompletionRequest } from ".";
// https://console.anthropic.com/docs/api/reference#-v1-complete // https://console.anthropic.com/docs/api/reference#-v1-complete
const AnthropicV1CompleteSchema = z.object({ const AnthropicV1CompleteSchema = z.object({
@ -42,8 +42,7 @@ export const transformOutboundPayload: ExpressHttpProxyReqCallback = (
_proxyReq, _proxyReq,
req req
) => { ) => {
if (req.retryCount > 0) { if (req.retryCount > 0 || !isCompletionRequest(req)) {
// We've already transformed the payload once, so don't do it again.
return; return;
} }