Update vscode language field in completion api. (#102)

add-tracing
Zhiming Ma 2023-04-13 21:42:59 +08:00 committed by GitHub
parent 83cecc9279
commit d5b6ea8187
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 13 deletions

View File

@ -10,7 +10,7 @@ import {
TextDocument,
workspace,
} from "vscode";
import { Language as SupportedLanguage, CompletionResponse, EventType, ChoiceEvent, ApiError } from "./generated";
import { CompletionResponse, EventType, ChoiceEvent, ApiError } from "./generated";
import { TabbyClient } from "./TabbyClient";
import { sleep } from "./utils";
@ -40,16 +40,6 @@ export class TabbyCompletionProvider implements InlineCompletionItemProvider {
return emptyResponse;
}
const languageId = document.languageId; // https://code.visualstudio.com/docs/languages/identifiers
let language = SupportedLanguage.UNKNOWN;
if (Object.values(SupportedLanguage).map(x => x.toString()).includes(languageId)) {
language = languageId as SupportedLanguage;
}
if (language == SupportedLanguage.UNKNOWN) {
console.debug(`Unsupported language '${languageId}', skipping`);
return emptyResponse;
}
const prompt = this.getPrompt(document, position);
if (this.isNil(prompt)) {
console.debug("Prompt is empty, skipping");
@ -77,7 +67,7 @@ export class TabbyCompletionProvider implements InlineCompletionItemProvider {
const completion = await this.tabbyClient.api.default.completionsV1CompletionsPost({
prompt: prompt as string, // Prompt is already nil-checked
language
language: document.languageId, // https://code.visualstudio.com/docs/languages/identifiers
}).then((response: CompletionResponse) => {
this.tabbyClient.changeStatus("ready");
return response;

View File

@ -1 +1 @@
{"openapi":"3.0.2","info":{"title":"TabbyServer","description":"\n[![github star](https://img.shields.io/github/stars/TabbyML/tabby?style=social)](http://github.com/TabbyML/tabby)\n\nTabbyServer is the backend for tabby, serving code completion requests from code editor / IDE.\n\n* [Admin Panel](./_admin)\n","version":"0.1.0"},"paths":{"/v1/completions":{"post":{"summary":"Completions","operationId":"completions_v1_completions_post","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CompletionRequest"}}},"required":true},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CompletionResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/v1/events":{"post":{"summary":"Events","operationId":"events_v1_events_post","requestBody":{"content":{"application/json":{"schema":{"title":"E","anyOf":[{"$ref":"#/components/schemas/ChoiceEvent"},{"$ref":"#/components/schemas/CompletionEvent"}]}}},"required":true},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}}},"components":{"schemas":{"Choice":{"title":"Choice","required":["index","text"],"type":"object","properties":{"index":{"title":"Index","type":"integer"},"text":{"title":"Text","type":"string"}}},"ChoiceEvent":{"title":"ChoiceEvent","required":["type","completion_id","choice_index"],"type":"object","properties":{"type":{"$ref":"#/components/schemas/EventType"},"completion_id":{"title":"Completion Id","type":"string"},"choice_index":{"title":"Choice Index","type":"integer"}}},"CompletionEvent":{"title":"CompletionEvent","required":["type","id","language","prompt","created","choices"],"type":"object","properties":{"type":{"$ref":"#/components/schemas/EventType"},"id":{"title":"Id","type":"string"},"language":{"$ref":"#/components/schemas/Language"},"prompt":{"title":"Prompt","type":"string"},"created":{"title":"Created","type":"integer"},"choices":{"title":"Choices","type":"array","items":{"$ref":"#/components/schemas/Choice"}}}},"CompletionRequest":{"title":"CompletionRequest","required":["prompt"],"type":"object","properties":{"language":{"allOf":[{"$ref":"#/components/schemas/Language"}],"description":"Language for completion request","default":"unknown","example":"python"},"prompt":{"title":"Prompt","type":"string","description":"The context to generate completions for, encoded as a string.","example":"def binarySearch(arr, left, right, x):\n mid = (left +"}}},"CompletionResponse":{"title":"CompletionResponse","required":["id","created","choices"],"type":"object","properties":{"id":{"title":"Id","type":"string"},"created":{"title":"Created","type":"integer"},"choices":{"title":"Choices","type":"array","items":{"$ref":"#/components/schemas/Choice"}}}},"EventType":{"title":"EventType","enum":["completion","view","select"],"type":"string","description":"An enumeration."},"HTTPValidationError":{"title":"HTTPValidationError","type":"object","properties":{"detail":{"title":"Detail","type":"array","items":{"$ref":"#/components/schemas/ValidationError"}}}},"Language":{"title":"Language","enum":["unknown","python","javascript","typescript"],"type":"string","description":"An enumeration."},"ValidationError":{"title":"ValidationError","required":["loc","msg","type"],"type":"object","properties":{"loc":{"title":"Location","type":"array","items":{"anyOf":[{"type":"string"},{"type":"integer"}]}},"msg":{"title":"Message","type":"string"},"type":{"title":"Error Type","type":"string"}}}}}}
{"openapi": "3.0.2", "info": {"title": "TabbyServer", "description": "\n[![github star](https://img.shields.io/github/stars/TabbyML/tabby?style=social)](http://github.com/TabbyML/tabby)\n\nTabbyServer is the backend for tabby, serving code completion requests from code editor / IDE.\n\n* [Admin Panel](./_admin)\n", "version": "0.1.0"}, "paths": {"/v1/completions": {"post": {"summary": "Completions", "operationId": "completions_v1_completions_post", "requestBody": {"content": {"application/json": {"schema": {"$ref": "#/components/schemas/CompletionRequest"}}}, "required": true}, "responses": {"200": {"description": "Successful Response", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/CompletionResponse"}}}}, "422": {"description": "Validation Error", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/HTTPValidationError"}}}}}}}, "/v1/events": {"post": {"summary": "Events", "operationId": "events_v1_events_post", "requestBody": {"content": {"application/json": {"schema": {"title": "E", "anyOf": [{"$ref": "#/components/schemas/ChoiceEvent"}, {"$ref": "#/components/schemas/CompletionEvent"}]}}}, "required": true}, "responses": {"200": {"description": "Successful Response", "content": {"application/json": {"schema": {}}}}, "422": {"description": "Validation Error", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/HTTPValidationError"}}}}}}}}, "components": {"schemas": {"Choice": {"title": "Choice", "required": ["index", "text"], "type": "object", "properties": {"index": {"title": "Index", "type": "integer"}, "text": {"title": "Text", "type": "string"}}}, "ChoiceEvent": {"title": "ChoiceEvent", "required": ["type", "completion_id", "choice_index"], "type": "object", "properties": {"type": {"$ref": "#/components/schemas/EventType"}, "completion_id": {"title": "Completion Id", "type": "string"}, "choice_index": {"title": "Choice Index", "type": "integer"}}}, "CompletionEvent": {"title": "CompletionEvent", "required": ["type", "id", "language", "prompt", "created", "choices"], "type": "object", "properties": {"type": {"$ref": "#/components/schemas/EventType"}, "id": {"title": "Id", "type": "string"}, "language": {"title": "Language", "type": "string"}, "prompt": {"title": "Prompt", "type": "string"}, "created": {"title": "Created", "type": "integer"}, "choices": {"title": "Choices", "type": "array", "items": {"$ref": "#/components/schemas/Choice"}}}}, "CompletionRequest": {"title": "CompletionRequest", "required": ["prompt"], "type": "object", "properties": {"language": {"title": "Language", "type": "string", "description": "Language for completion request", "default": "unknown", "example": "python"}, "prompt": {"title": "Prompt", "type": "string", "description": "The context to generate completions for, encoded as a string.", "example": "def binarySearch(arr, left, right, x):\n mid = (left +"}}}, "CompletionResponse": {"title": "CompletionResponse", "required": ["id", "created", "choices"], "type": "object", "properties": {"id": {"title": "Id", "type": "string"}, "created": {"title": "Created", "type": "integer"}, "choices": {"title": "Choices", "type": "array", "items": {"$ref": "#/components/schemas/Choice"}}}}, "EventType": {"title": "EventType", "enum": ["completion", "view", "select"], "type": "string", "description": "An enumeration."}, "HTTPValidationError": {"title": "HTTPValidationError", "type": "object", "properties": {"detail": {"title": "Detail", "type": "array", "items": {"$ref": "#/components/schemas/ValidationError"}}}}, "ValidationError": {"title": "ValidationError", "required": ["loc", "msg", "type"], "type": "object", "properties": {"loc": {"title": "Location", "type": "array", "items": {"anyOf": [{"type": "string"}, {"type": "integer"}]}}, "msg": {"title": "Message", "type": "string"}, "type": {"title": "Error Type", "type": "string"}}}}}}