From 8456b24318b13ea5d5dabec2328dd854f8a492b4 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Wed, 9 Aug 2023 22:04:22 -0700 Subject: feat: :sparkles: support for Together.ai models --- continuedev/src/continuedev/libs/llm/ggml.py | 5 +- continuedev/src/continuedev/libs/llm/replicate.py | 2 +- continuedev/src/continuedev/libs/llm/together.py | 118 ++++++++++++++++++++++ 3 files changed, 123 insertions(+), 2 deletions(-) create mode 100644 continuedev/src/continuedev/libs/llm/together.py (limited to 'continuedev/src') diff --git a/continuedev/src/continuedev/libs/llm/ggml.py b/continuedev/src/continuedev/libs/llm/ggml.py index 2f131354..25a61e63 100644 --- a/continuedev/src/continuedev/libs/llm/ggml.py +++ b/continuedev/src/continuedev/libs/llm/ggml.py @@ -82,7 +82,10 @@ class GGML(LLM): chunks = json_chunk.split("\n") for chunk in chunks: if chunk.strip() != "": - yield json.loads(chunk[6:])["choices"][0]["delta"] + yield { + "role": "assistant", + "content": json.loads(chunk[6:])["choices"][0]["delta"] + } except: raise Exception(str(line[0])) diff --git a/continuedev/src/continuedev/libs/llm/replicate.py b/continuedev/src/continuedev/libs/llm/replicate.py index 235fd906..0dd359e7 100644 --- a/continuedev/src/continuedev/libs/llm/replicate.py +++ b/continuedev/src/continuedev/libs/llm/replicate.py @@ -25,7 +25,7 @@ class ReplicateLLM(LLM): @property def default_args(self): - return {**DEFAULT_ARGS, "model": self.name, "max_tokens": 1024} + return {**DEFAULT_ARGS, "model": self.model, "max_tokens": 1024} def count_tokens(self, text: str): return count_tokens(self.name, text) diff --git a/continuedev/src/continuedev/libs/llm/together.py b/continuedev/src/continuedev/libs/llm/together.py new file mode 100644 index 00000000..1cc0a711 --- /dev/null +++ b/continuedev/src/continuedev/libs/llm/together.py @@ -0,0 +1,118 @@ +import json +from typing import Any, Coroutine, Dict, Generator, List, Union + +import aiohttp +from ...core.main import ChatMessage +from ..llm import LLM +from ..util.count_tokens import compile_chat_messages, DEFAULT_ARGS, count_tokens + + +class TogetherLLM(LLM): + # this is model-specific + api_key: str + model: str = "togethercomputer/RedPajama-INCITE-7B-Instruct" + max_context_length: int = 2048 + base_url: str = "https://api.together.xyz" + verify_ssl: bool = True + + _client_session: aiohttp.ClientSession = None + + async def start(self, **kwargs): + self._client_session = aiohttp.ClientSession( + connector=aiohttp.TCPConnector(verify_ssl=self.verify_ssl)) + + async def stop(self): + await self._client_session.close() + + @property + def name(self): + return self.model + + @property + def context_length(self): + return self.max_context_length + + @property + def default_args(self): + return {**DEFAULT_ARGS, "model": self.model, "max_tokens": 1024} + + def count_tokens(self, text: str): + return count_tokens(self.name, text) + + def convert_to_prompt(self, chat_messages: List[ChatMessage]) -> str: + system_message = None + if chat_messages[0]["role"] == "system": + system_message = chat_messages.pop(0)["content"] + + prompt = "\n" + if system_message: + prompt += f": Hi!\n: {system_message}\n" + for message in chat_messages: + prompt += f'<{"human" if message["role"] == "user" else "bot"}>: {message["content"]}\n' + return prompt + + async def stream_complete(self, prompt, with_history: List[ChatMessage] = None, **kwargs) -> Generator[Union[Any, List, Dict], None, None]: + args = self.default_args.copy() + args.update(kwargs) + args["stream_tokens"] = True + + args = {**self.default_args, **kwargs} + messages = compile_chat_messages( + self.name, with_history, self.context_length, args["max_tokens"], prompt, functions=args.get("functions", None), system_message=self.system_message) + + async with self._client_session.post(f"{self.base_url}/inference", json={ + "prompt": self.convert_to_prompt(messages), + **args + }, headers={ + "Authorization": f"Bearer {self.api_key}" + }) as resp: + async for line in resp.content.iter_any(): + if line: + try: + yield line.decode("utf-8") + except: + raise Exception(str(line)) + + async def stream_chat(self, messages: List[ChatMessage] = None, **kwargs) -> Generator[Union[Any, List, Dict], None, None]: + args = {**self.default_args, **kwargs} + messages = compile_chat_messages( + self.name, messages, self.context_length, args["max_tokens"], None, functions=args.get("functions", None), system_message=self.system_message) + args["stream_tokens"] = True + + async with self._client_session.post(f"{self.base_url}/inference", json={ + "prompt": self.convert_to_prompt(messages), + **args + }, headers={ + "Authorization": f"Bearer {self.api_key}" + }) as resp: + async for line in resp.content.iter_chunks(): + if line[1]: + try: + json_chunk = line[0].decode("utf-8") + if json_chunk.startswith(": ping - ") or json_chunk.startswith("data: [DONE]"): + continue + chunks = json_chunk.split("\n") + for chunk in chunks: + if chunk.strip() != "": + yield { + "role": "assistant", + "content": json.loads(chunk[6:])["choices"][0]["text"] + } + except: + raise Exception(str(line[0])) + + async def complete(self, prompt: str, with_history: List[ChatMessage] = None, **kwargs) -> Coroutine[Any, Any, str]: + args = {**self.default_args, **kwargs} + + messages = compile_chat_messages(args["model"], with_history, self.context_length, + args["max_tokens"], prompt, functions=None, system_message=self.system_message) + async with self._client_session.post(f"{self.base_url}/inference", json={ + "prompt": self.convert_to_prompt(messages), + **args + }, headers={ + "Authorization": f"Bearer {self.api_key}" + }) as resp: + try: + return await resp.text() + except: + raise Exception(await resp.text()) -- cgit v1.2.3-70-g09d2 From cbd7656bb4c9aebfe98c746111af52cf7192aa1b Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Wed, 9 Aug 2023 22:22:46 -0700 Subject: feat: :sparkles: testing in ci, final test of --- .github/workflows/main.yaml | 49 ++++++++++-------------- continuedev/src/continuedev/libs/llm/together.py | 6 ++- 2 files changed, 25 insertions(+), 30 deletions(-) (limited to 'continuedev/src') diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 6111856d..9bc05281 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -45,7 +45,7 @@ jobs: name: ${{ runner.os }} Build path: dist/* - test-and-package: + test-and-publish-extension: needs: pyinstaller strategy: matrix: @@ -135,51 +135,42 @@ jobs: npm run test if: matrix.os != 'ubuntu-20.04' - # Upload .vsix artifact - - - name: Upload .vsix as an artifact - uses: actions/upload-artifact@v2 - with: - name: vsix-artifact - path: extension/build/* - if: matrix.os == 'ubuntu-20.04' - - publish: - needs: test-and-package - runs-on: ubuntu-20.04 - permissions: - contents: write - - steps: - # Checkout and download .vsix artifact - - - name: Checkout - uses: actions/checkout@v2 - - - name: Download .vsix artifact - uses: actions/download-artifact@v2 - with: - name: vsix-artifact - path: extension/build - - # Publish the extension and commit/push the version change + # Publish the extension and commit/push the version change (ONLY on ubuntu-20.04) - name: Publish run: | cd extension npx vsce publish patch -p ${{ secrets.VSCE_TOKEN }} + if: matrix.os == 'ubuntu-20.04' + - name: Commit changes run: | git config --local user.email "action@github.com" git config --local user.name "GitHub Action" git commit -am "ci: 💚 Update package.json version [skip ci]" + if: matrix.os == 'ubuntu-20.04' - name: Push changes uses: ad-m/github-push-action@master with: github_token: ${{ secrets.GITHUB_TOKEN }} branch: ${{ github.ref }} + if: matrix.os == 'ubuntu-20.04' + + - name: Upload .vsix as an artifact + uses: actions/upload-artifact@v2 + with: + name: vsix-artifact + path: extension/build/* + if: matrix.os == 'ubuntu-20.04' + publish-binaries: + needs: test-and-publish-extension + runs-on: ubuntu-20.04 + permissions: + contents: write + + steps: # Download binaries and upload to S3 - name: Download Linux build diff --git a/continuedev/src/continuedev/libs/llm/together.py b/continuedev/src/continuedev/libs/llm/together.py index 1cc0a711..c3f171c9 100644 --- a/continuedev/src/continuedev/libs/llm/together.py +++ b/continuedev/src/continuedev/libs/llm/together.py @@ -49,6 +49,8 @@ class TogetherLLM(LLM): prompt += f": Hi!\n: {system_message}\n" for message in chat_messages: prompt += f'<{"human" if message["role"] == "user" else "bot"}>: {message["content"]}\n' + + prompt += ":" return prompt async def stream_complete(self, prompt, with_history: List[ChatMessage] = None, **kwargs) -> Generator[Union[Any, List, Dict], None, None]: @@ -113,6 +115,8 @@ class TogetherLLM(LLM): "Authorization": f"Bearer {self.api_key}" }) as resp: try: - return await resp.text() + text = await resp.text() + j = json.loads(text) + return j["output"]["choices"][0]["text"] except: raise Exception(await resp.text()) -- cgit v1.2.3-70-g09d2 From 19acf3bb36c1e44274297c806b89b589ca02f5ba Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Thu, 10 Aug 2023 10:47:09 -0700 Subject: fix: :green_heart: testing for failure to package dist in vsix --- .github/workflows/main.yaml | 108 ++++++++++++---------- continuedev/src/continuedev/plugins/steps/help.py | 3 +- extension/react-app/src/components/ComboBox.tsx | 3 +- extension/scripts/package.js | 6 ++ 4 files changed, 68 insertions(+), 52 deletions(-) (limited to 'continuedev/src') diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 99b30201..03855b64 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -180,55 +180,63 @@ jobs: cd extension npm ci - - name: Publish - run: | - cd extension - npx vsce publish patch -p ${{ secrets.VSCE_TOKEN }} - - name: Commit changes - run: | - git config --local user.email "action@github.com" - git config --local user.name "GitHub Action" - git commit -am "ci: 💚 Update package.json version [skip ci]" - - name: Push changes - uses: ad-m/github-push-action@master - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - branch: ${{ github.ref }} - - # Download binaries and upload to S3 - - - name: Download Linux build - uses: actions/download-artifact@v2 - with: - name: Linux Build - path: exe/linux - - - name: Download macOS build - uses: actions/download-artifact@v2 - with: - name: macOS Build - path: exe/mac - - - name: Download Windows build - uses: actions/download-artifact@v2 - with: - name: Windows Build - path: exe/windows - - - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v1 + - name: Upload .vsix a second time + uses: actions/upload-artifact@v2 with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: us-west-1 + name: vsix-artifact + path: extension/build - - name: Upload binaries to S3 - uses: jakejarvis/s3-sync-action@master - with: - args: --acl public-read --follow-symlinks --delete - env: - AWS_S3_BUCKET: continue-server-binaries - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - AWS_REGION: "us-west-1" - SOURCE_DIR: "exe" + # - name: Publish + # run: | + # cd extension + # npx vsce publish patch -p ${{ secrets.VSCE_TOKEN }} + + # - name: Commit changes + # run: | + # git config --local user.email "action@github.com" + # git config --local user.name "GitHub Action" + # git commit -am "ci: 💚 Update package.json version [skip ci]" + + # - name: Push changes + # uses: ad-m/github-push-action@master + # with: + # github_token: ${{ secrets.GITHUB_TOKEN }} + # branch: ${{ github.ref }} + + # # Download binaries and upload to S3 + + # - name: Download Linux build + # uses: actions/download-artifact@v2 + # with: + # name: Linux Build + # path: exe/linux + + # - name: Download macOS build + # uses: actions/download-artifact@v2 + # with: + # name: macOS Build + # path: exe/mac + + # - name: Download Windows build + # uses: actions/download-artifact@v2 + # with: + # name: Windows Build + # path: exe/windows + + # - name: Configure AWS Credentials + # uses: aws-actions/configure-aws-credentials@v1 + # with: + # aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + # aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + # aws-region: us-west-1 + + # - name: Upload binaries to S3 + # uses: jakejarvis/s3-sync-action@master + # with: + # args: --acl public-read --follow-symlinks --delete + # env: + # AWS_S3_BUCKET: continue-server-binaries + # AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + # AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + # AWS_REGION: "us-west-1" + # SOURCE_DIR: "exe" diff --git a/continuedev/src/continuedev/plugins/steps/help.py b/continuedev/src/continuedev/plugins/steps/help.py index ec670999..82f885d6 100644 --- a/continuedev/src/continuedev/plugins/steps/help.py +++ b/continuedev/src/continuedev/plugins/steps/help.py @@ -39,6 +39,7 @@ class HelpStep(Step): if question.strip() == "": self.description = help else: + self.description = "The following output is generated by a language model, which may hallucinate. Type just '/help'to see a fixed answer. You can also learn more by reading [the docs](https://continue.dev/docs).\n\n" prompt = dedent(f""" Information: @@ -48,7 +49,7 @@ class HelpStep(Step): Please us the information below to provide a succinct answer to the following question: {question} - Do not cite any slash commands other than those you've been told about, which are: /edit and /feedback.""") + Do not cite any slash commands other than those you've been told about, which are: /edit and /feedback. Never refer or link to any URL.""") self.chat_context.append(ChatMessage( role="user", diff --git a/extension/react-app/src/components/ComboBox.tsx b/extension/react-app/src/components/ComboBox.tsx index 472e1b14..bf32fc5a 100644 --- a/extension/react-app/src/components/ComboBox.tsx +++ b/extension/react-app/src/components/ComboBox.tsx @@ -479,7 +479,8 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => { selected={downshiftProps.selectedItem === item} > - {item.name}:{" "} + {item.name} + {" "} {item.description} diff --git a/extension/scripts/package.js b/extension/scripts/package.js index ae9a4d94..e36df029 100644 --- a/extension/scripts/package.js +++ b/extension/scripts/package.js @@ -17,6 +17,12 @@ exec("npm install", (error) => { exec("npm run build", (error) => { if (error) throw error; + if (!fs.existsSync(path.join("dist", "assets", "index.js"))) { + throw new Error("react-app build did not produce index.js"); + } + if (!fs.existsSync(path.join("dist", "assets", "index.css"))) { + throw new Error("react-app build did not produce index.css"); + } console.log("npm run build in react-app completed"); process.chdir(".."); -- cgit v1.2.3-70-g09d2