Support OpenAI-compatible inference endpoints
This commit is contained in:
@@ -24,6 +24,22 @@ class Handler(BaseHTTPRequestHandler):
|
||||
message = self.body()
|
||||
method = message.get('method')
|
||||
args = message.get('params', {})
|
||||
if self.path == '/compatible/v1/chat/completions':
|
||||
if self.headers.get('Authorization') != 'Bearer fixture-token':
|
||||
self.reply(401)
|
||||
return
|
||||
assert message['stream'] and message['model'] == 'fixture-model'
|
||||
assert message['messages'][0] == {'role': 'system', 'content': 'Silent instruction'}
|
||||
assert message['temperature'] == 0 and message['max_tokens'] == 32
|
||||
assert 'options' not in message and 'think' not in message
|
||||
frames = [
|
||||
{'choices': [{'delta': {'reasoning_content': 'Thinking'}}]},
|
||||
{'choices': [{'delta': {'content': 'Fixture response'}}]},
|
||||
{'choices': [{'delta': {}, 'finish_reason': 'stop'}]},
|
||||
]
|
||||
payload = ''.join(f'data: {json.dumps(frame)}\n\n' for frame in frames)
|
||||
self.reply(200, (payload + 'data: [DONE]\n\n').encode(), 'text/event-stream')
|
||||
return
|
||||
if self.path == '/gateway/api/chat':
|
||||
if self.headers.get('Authorization') != 'Bearer fixture-token':
|
||||
self.reply(401)
|
||||
@@ -80,6 +96,12 @@ class Handler(BaseHTTPRequestHandler):
|
||||
self.reply(200, envelope, headers=headers)
|
||||
|
||||
def do_GET(self):
|
||||
if self.path == '/compatible/v1/models':
|
||||
if self.headers.get('Authorization') != 'Bearer fixture-token':
|
||||
self.reply(401)
|
||||
return
|
||||
self.reply(200, {'data': [{'id': 'fixture-model'}, {'id': 'fixture-model'}]})
|
||||
return
|
||||
if self.path == '/gateway/api/tags':
|
||||
if self.headers.get('Authorization') != 'Bearer fixture-token':
|
||||
self.reply(401)
|
||||
|
||||
Reference in New Issue
Block a user