make sdk.models blocking
This commit is contained in:
parent
2c151796aa
commit
6f39aeb106
10 changed files with 28 additions and 20 deletions
|
|
@ -1,4 +1,6 @@
|
|||
from abc import ABC, abstractmethod
|
||||
import asyncio
|
||||
from functools import cached_property
|
||||
from typing import Coroutine, Union
|
||||
import os
|
||||
|
||||
|
|
@ -29,15 +31,21 @@ class Models:
|
|||
def __init__(self, sdk: "ContinueSDK"):
|
||||
self.sdk = sdk
|
||||
|
||||
async def starcoder(self):
|
||||
api_key = await self.sdk.get_user_secret(
|
||||
'HUGGING_FACE_TOKEN', 'Please add your Hugging Face token to the .env file')
|
||||
return HuggingFaceInferenceAPI(api_key=api_key)
|
||||
@cached_property
|
||||
def starcoder(self):
|
||||
async def load_starcoder():
|
||||
api_key = await self.sdk.get_user_secret(
|
||||
'HUGGING_FACE_TOKEN', 'Please add your Hugging Face token to the .env file')
|
||||
return HuggingFaceInferenceAPI(api_key=api_key)
|
||||
return asyncio.get_event_loop().run_until_complete(load_starcoder())
|
||||
|
||||
async def gpt35(self):
|
||||
api_key = await self.sdk.get_user_secret(
|
||||
'OPENAI_API_KEY', 'Please add your OpenAI API key to the .env file')
|
||||
return OpenAI(api_key=api_key, default_model="gpt-3.5-turbo")
|
||||
@cached_property
|
||||
def gpt35(self):
|
||||
async def load_gpt35():
|
||||
api_key = await self.sdk.get_user_secret(
|
||||
'OPENAI_API_KEY', 'Please add your OpenAI API key to the .env file')
|
||||
return OpenAI(api_key=api_key, default_model="gpt-3.5-turbo")
|
||||
return asyncio.get_event_loop().run_until_complete(load_gpt35())
|
||||
|
||||
|
||||
class ContinueSDK(AbstractContinueSDK):
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ class SetupPipelineStep(Step):
|
|||
async def run(self, sdk: ContinueSDK):
|
||||
sdk.context.set("api_description", self.api_description)
|
||||
|
||||
source_name = (await sdk.models.gpt35()).complete(
|
||||
source_name = sdk.models.gpt35.complete(
|
||||
f"Write a snake_case name for the data source described by {self.api_description}: ").strip()
|
||||
filename = f'{source_name}.py'
|
||||
|
||||
|
|
@ -92,7 +92,7 @@ class ValidatePipelineStep(Step):
|
|||
if "Traceback" in output or "SyntaxError" in output:
|
||||
output = "Traceback" + output.split("Traceback")[-1]
|
||||
file_content = await sdk.ide.readFile(os.path.join(workspace_dir, filename))
|
||||
suggestion = (await sdk.models.gpt35()).complete(dedent(f"""\
|
||||
suggestion = sdk.models.gpt35.complete(dedent(f"""\
|
||||
```python
|
||||
{file_content}
|
||||
```
|
||||
|
|
@ -104,7 +104,7 @@ class ValidatePipelineStep(Step):
|
|||
|
||||
This is a brief summary of the error followed by a suggestion on how it can be fixed by editing the resource function:"""))
|
||||
|
||||
api_documentation_url = (await sdk.models.gpt35()).complete(dedent(f"""\
|
||||
api_documentation_url = sdk.models.gpt35.complete(dedent(f"""\
|
||||
The API I am trying to call is the '{sdk.context.get('api_description')}'. I tried calling it in the @resource function like this:
|
||||
```python
|
||||
{file_content}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ class WritePytestsRecipe(Step):
|
|||
"{self.instructions}"
|
||||
|
||||
Here is a complete set of pytest unit tests:""")
|
||||
tests = (await sdk.models.gpt35()).complete(prompt)
|
||||
tests = sdk.models.gpt35.complete(prompt)
|
||||
|
||||
await sdk.apply_filesystem_edit(AddFile(filepath=path, content=tests))
|
||||
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ class AnswerQuestionChroma(Step):
|
|||
|
||||
Here is the answer:""")
|
||||
|
||||
answer = (await sdk.models.gpt35()).complete(prompt)
|
||||
answer = sdk.models.gpt35.complete(prompt)
|
||||
# Make paths relative to the workspace directory
|
||||
answer = answer.replace(await sdk.ide.getWorkspaceDirectory(), "")
|
||||
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ class Gpt35EditCodeStep(Step):
|
|||
prompt = self._prompt.format(
|
||||
code=rif.contents, user_request=self.user_input, file_prefix=segs[0], file_suffix=segs[1])
|
||||
|
||||
completion = str((await sdk.models.gpt35()).complete(prompt))
|
||||
completion = str(sdk.models.gpt35.complete(prompt))
|
||||
eot_token = "<|endoftext|>"
|
||||
completion = completion.removesuffix(eot_token)
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ class MigrationStep(Step):
|
|||
recent_edits = await sdk.ide.get_recent_edits(self.edited_file)
|
||||
recent_edits_string = "\n\n".join(
|
||||
map(lambda x: x.to_string(), recent_edits))
|
||||
description = await (await sdk.models.gpt35()).complete(f"{recent_edits_string}\n\nGenerate a short description of the migration made in the above changes:\n")
|
||||
description = await sdk.models.gpt35.complete(f"{recent_edits_string}\n\nGenerate a short description of the migration made in the above changes:\n")
|
||||
await sdk.run([
|
||||
"cd libs",
|
||||
"poetry run alembic revision --autogenerate -m " + description,
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ class FasterEditHighlightedCodeStep(Step):
|
|||
for rif in rif_with_contents:
|
||||
rif_dict[rif.filepath] = rif.contents
|
||||
|
||||
completion = (await sdk.models.gpt35()).complete(prompt)
|
||||
completion = sdk.models.gpt35.complete(prompt)
|
||||
|
||||
# Temporarily doing this to generate description.
|
||||
self._prompt = prompt
|
||||
|
|
@ -239,7 +239,7 @@ class StarCoderEditHighlightedCodeStep(Step):
|
|||
for rif in rif_with_contents:
|
||||
prompt = self._prompt.format(
|
||||
code=rif.contents, user_request=self.user_input)
|
||||
completion = str((await sdk.models.starcoder()).complete(prompt))
|
||||
completion = str(sdk.models.starcoder.complete(prompt))
|
||||
eot_token = "<|endoftext|>"
|
||||
if completion.endswith(eot_token):
|
||||
completion = completion[:completion.rindex(eot_token)]
|
||||
|
|
|
|||
4
extension/package-lock.json
generated
4
extension/package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "continue",
|
||||
"version": "0.0.23",
|
||||
"version": "0.0.24",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "continue",
|
||||
"version": "0.0.23",
|
||||
"version": "0.0.24",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@electron/rebuild": "^3.2.10",
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
"displayName": "Continue",
|
||||
"pricing": "Free",
|
||||
"description": "Refine code 10x faster",
|
||||
"version": "0.0.23",
|
||||
"version": "0.0.24",
|
||||
"publisher": "Continue",
|
||||
"engines": {
|
||||
"vscode": "^1.74.0"
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Add table
Reference in a new issue