cloving 0.3.19 → 0.3.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/dist/index.js +2 -0
  2. package/dist/managers/CommitManager.js +30 -16
  3. package/dist/package.json +1 -1
  4. package/package.json +1 -1
  5. package/.DS_Store +0 -0
  6. package/.aider.chat.history.md +0 -16978
  7. package/.aider.input.history +0 -15
  8. package/.aider.tags.cache.v3/cache.db +0 -0
  9. package/.aider.tags.cache.v3/cache.db-shm +0 -0
  10. package/.aider.tags.cache.v3/cache.db-wal +0 -0
  11. package/.cursorrules +0 -77
  12. package/.github/workflows/auto-release.yml +0 -83
  13. package/.github/workflows/ci.yml +0 -32
  14. package/.github/workflows/npm-publish.yml +0 -34
  15. package/.gitignore +0 -67
  16. package/.husky/_/.gitignore +0 -1
  17. package/.husky/_/applypatch-msg +0 -2
  18. package/.husky/_/commit-msg +0 -2
  19. package/.husky/_/h +0 -22
  20. package/.husky/_/husky.sh +0 -9
  21. package/.husky/_/post-applypatch +0 -2
  22. package/.husky/_/post-checkout +0 -2
  23. package/.husky/_/post-commit +0 -2
  24. package/.husky/_/post-merge +0 -2
  25. package/.husky/_/post-rewrite +0 -2
  26. package/.husky/_/pre-applypatch +0 -2
  27. package/.husky/_/pre-auto-gc +0 -2
  28. package/.husky/_/pre-commit +0 -2
  29. package/.husky/_/pre-merge-commit +0 -2
  30. package/.husky/_/pre-push +0 -2
  31. package/.husky/_/pre-rebase +0 -2
  32. package/.husky/_/prepare-commit-msg +0 -2
  33. package/.husky/pre-commit +0 -1
  34. package/.husky/pre-push +0 -1
  35. package/.prettierrc.json +0 -7
  36. package/.tool-versions +0 -2
  37. package/SECURITY.md +0 -15
  38. package/cloving.json +0 -67
  39. package/jest.config.js +0 -11
  40. package/src/cloving_gpt/adapters/azureopenai.ts +0 -83
  41. package/src/cloving_gpt/adapters/claude.ts +0 -140
  42. package/src/cloving_gpt/adapters/gemini.ts +0 -146
  43. package/src/cloving_gpt/adapters/index.ts +0 -43
  44. package/src/cloving_gpt/adapters/mistral.ts +0 -142
  45. package/src/cloving_gpt/adapters/ollama.ts +0 -136
  46. package/src/cloving_gpt/adapters/openai.ts +0 -113
  47. package/src/cloving_gpt/index.ts +0 -229
  48. package/src/commands/chat.ts +0 -12
  49. package/src/commands/config.ts +0 -192
  50. package/src/commands/generate/code.ts +0 -18
  51. package/src/commands/generate/commit.ts +0 -9
  52. package/src/commands/generate/context.ts +0 -93
  53. package/src/commands/generate/docs.ts +0 -9
  54. package/src/commands/generate/review.ts +0 -9
  55. package/src/commands/generate/shell.ts +0 -9
  56. package/src/commands/generate/unit_tests.ts +0 -9
  57. package/src/commands/init.ts +0 -9
  58. package/src/commands/models.ts +0 -21
  59. package/src/commands/proxy.ts +0 -9
  60. package/src/commands/tokens.ts +0 -82
  61. package/src/index.ts +0 -197
  62. package/src/managers/BlockManager.ts +0 -126
  63. package/src/managers/ChatManager.ts +0 -755
  64. package/src/managers/ChunkManager.ts +0 -31
  65. package/src/managers/CodeManager.ts +0 -226
  66. package/src/managers/CommitManager.ts +0 -71
  67. package/src/managers/DocsManager.ts +0 -101
  68. package/src/managers/InitManager.ts +0 -263
  69. package/src/managers/ProxyManager.ts +0 -240
  70. package/src/managers/ReviewManager.ts +0 -154
  71. package/src/managers/ShellManager.ts +0 -172
  72. package/src/managers/StreamManager.ts +0 -353
  73. package/src/managers/UnitTestManager.ts +0 -293
  74. package/src/utils/config_utils.ts +0 -271
  75. package/src/utils/git_utils.ts +0 -230
  76. package/src/utils/model_utils.ts +0 -3
  77. package/src/utils/prompt_utils.ts +0 -375
  78. package/src/utils/prompts/CODEGEN_COULDNT_APPLY.md +0 -5
  79. package/src/utils/prompts/CODEGEN_EXAMPLES.md +0 -82
  80. package/src/utils/prompts/CODEGEN_INSTRUCTIONS.md +0 -43
  81. package/src/utils/prompts/DOCS_INSTRUCTIONS.md +0 -9
  82. package/src/utils/prompts/INIT_INSTRUCTIONS.md +0 -132
  83. package/src/utils/prompts/REVIEW_INSTRUCTIONS.md +0 -49
  84. package/src/utils/prompts/SHELL_INSTRUCTIONS.md +0 -15
  85. package/src/utils/prompts/SPECIAL_FILES.md +0 -66
  86. package/src/utils/prompts/index.ts +0 -37
  87. package/src/utils/string_utils.ts +0 -552
  88. package/src/utils/types.ts +0 -127
  89. package/tests/commands/generate/unit_tests.test.ts +0 -27
  90. package/tests/utils/git_utils.test.ts +0 -116
  91. package/tests/utils/model_utils.test.ts +0 -27
  92. package/tests/utils/prompt_utils.test.ts +0 -33
  93. package/tests/utils/string_utils.test.ts +0 -560
  94. package/tsconfig.json +0 -14
  95. package/yarn.lock +0 -5823
@@ -1,15 +0,0 @@
1
-
2
- # 2024-08-11 14:44:54.497516
3
- +move the logic for `src/commands/generate/commit.ts` into a CommitManager.ts similar to how `src/managers/CodeManager.ts`
4
-
5
- # 2024-08-11 14:47:53.307920
6
- +can you make CommitM
7
-
8
- # 2024-08-12 07:34:19.616951
9
- +what is 1+1?
10
-
11
- # 2024-08-13 16:41:12.331108
12
- +fix `src/managers/ReviewManager.ts` to use the private chatHistory: ChatMessage[] like `src/managers/CodeManager.ts`
13
-
14
- # 2024-08-13 16:43:18.098654
15
- +how do I modify `src/utils/command_utils.ts` generateCodegenPrompt to make sure that the CURRENT in a *CURRENT/NEW* Block is as small as possible and does not try to include large chunks of unneeded code to replace
Binary file
Binary file
File without changes
package/.cursorrules DELETED
@@ -1,77 +0,0 @@
1
- # TypeScript-specific coding standards
2
- typescript:
3
- style:
4
- quotes: 'single' # Use single quotes for strings
5
- semi: false # No semicolons at end of statements
6
- trailingComma: 'all' # Add trailing commas wherever possible
7
- printWidth: 100 # Maximum line length before wrapping
8
- tabWidth: 2 # Number of spaces for each indentation level
9
- bracketSpacing: true # Spaces between brackets in object literals
10
- arrowParens: 'avoid' # Omit parentheses for single arrow function parameters
11
-
12
- imports:
13
- preferNamed: true # Prefer named imports over default imports
14
- grouping: # Order of import groups
15
- - '^@/' # Internal modules first
16
- - '^[./]' # Relative imports second
17
- maxLineLength: 100 # Maximum length for import statements
18
- sortImports: true # Sort imports alphabetically within groups
19
- newlineAfterImports: true # Add newline after import section
20
-
21
- naming:
22
- classes: 'PascalCase' # Example: UserService, ConfigManager
23
- interfaces: 'PascalCase' # Example: UserInterface, ConfigOptions
24
- types: 'PascalCase' # Example: UserType, ConfigType
25
- enums: 'PascalCase' # Example: UserRole, LogLevel
26
- variables: 'camelCase' # Example: userData, configSettings
27
- functions: 'camelCase' # Example: getData(), processConfig()
28
- constants: 'UPPER_CASE' # Example: API_KEY, MAX_RETRIES
29
- privateMembers: 'camelCase' # Example: private myPrivateVar
30
- typeParameters: 'PascalCase' # Example: <T>, <TKey>
31
-
32
- organization:
33
- preferConst: true # Use const by default, let only when necessary
34
- maxParametersPerFunction: 4 # Limit function parameters for better readability
35
- maxFunctionLength: 50 # Keep functions concise and focused
36
- memberOrdering: # Class member ordering
37
- - 'public-static-field'
38
- - 'private-static-field'
39
- - 'public-instance-field'
40
- - 'private-instance-field'
41
- - 'constructor'
42
- - 'public-instance-method'
43
- - 'private-instance-method'
44
-
45
- documentation:
46
- jsdocStyle: true # Use JSDoc style comments for documentation
47
- requireParamTypes: true # Require type annotations in @param tags
48
- requireReturnType: true # Require return type annotations
49
- requireExampleComments: true # Include examples in complex function docs
50
- multilineCommentStyle: # Style for multiline comments
51
- startsWith: '/**' # Start with /** for JSDoc comments
52
- linePrefix: ' * ' # Each line starts with ' * '
53
- endsWith: ' */' # End with */
54
-
55
- # General project-wide settings
56
- general:
57
- fileNaming: 'kebab-case' # Example: user-service.ts, config-manager.ts
58
- directoryNaming: 'kebab-case' # Example: user-services/, config-utils/
59
- maxLineLength: 100 # Maximum characters per line
60
- indentation: 'spaces' # Use spaces instead of tabs
61
- indentSize: 2 # Number of spaces per indentation level
62
- newlineAtEndOfFile: true # Ensure files end with a newline
63
-
64
- patterns:
65
- utils:
66
- location: 'src/utils' # Utility functions go in src/utils
67
- naming: '${name}_utils' # Example: string_utils.ts, file_utils.ts
68
- managers:
69
- location: 'src/managers' # Manager classes go in src/managers
70
- naming: '${Name}Manager' # Example: ChatManager.ts, StreamManager.ts
71
- types:
72
- location: 'src/utils/types.ts' # Central types file
73
- constants:
74
- location: 'src/utils/constants.ts' # Central constants file
75
- tests:
76
- location: 'tests' # Test files in tests directory
77
- naming: '${name}.test.ts' # Example: string_utils.test.ts
@@ -1,83 +0,0 @@
1
- name: Auto Release
2
-
3
- on:
4
- push:
5
- branches:
6
- - main
7
-
8
- jobs:
9
- test:
10
- runs-on: ubuntu-latest
11
-
12
- strategy:
13
- matrix:
14
- node-version: ['20.x', '22.x']
15
-
16
- steps:
17
- - name: Checkout code
18
- uses: actions/checkout@v3
19
-
20
- - name: Set up Node.js
21
- uses: actions/setup-node@v3
22
- with:
23
- node-version: ${{ matrix.node-version }}
24
-
25
- - name: Install dependencies
26
- run: yarn install
27
-
28
- - name: Run TypeScript checks
29
- run: yarn run check
30
-
31
- - name: Run tests
32
- run: yarn run test
33
-
34
- check-version-and-release:
35
- needs: test
36
- runs-on: ubuntu-latest
37
- steps:
38
- - name: Checkout code
39
- uses: actions/checkout@v4
40
- with:
41
- fetch-depth: 0
42
-
43
- - name: Get current version
44
- id: package-version
45
- run: echo "::set-output name=version::$(node -p "require('./package.json').version")"
46
-
47
- - name: Get latest release version
48
- id: latest-release
49
- run: |
50
- latest_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
51
- echo "::set-output name=version::${latest_tag#v}"
52
-
53
- - name: Compare versions
54
- id: compare-versions
55
- run: |
56
- if [ "${{ steps.package-version.outputs.version }}" != "${{ steps.latest-release.outputs.version }}" ]; then
57
- echo "::set-output name=changed::true"
58
- else
59
- echo "::set-output name=changed::false"
60
- fi
61
-
62
- - name: Generate changelog
63
- if: steps.compare-versions.outputs.changed == 'true'
64
- id: changelog
65
- uses: metcalfc/changelog-generator@v4.3.1
66
- with:
67
- myToken: ${{ secrets.GITHUB_TOKEN }}
68
- head-ref: v${{ steps.package-version.outputs.version }}
69
- base-ref: v${{ steps.latest-release.outputs.version }}
70
-
71
- - name: Create Release
72
- if: steps.compare-versions.outputs.changed == 'true'
73
- uses: actions/create-release@v1
74
- env:
75
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
76
- with:
77
- tag_name: v${{ steps.package-version.outputs.version }}
78
- release_name: Release v${{ steps.package-version.outputs.version }}
79
- body: |
80
- Changes in this Release:
81
- ${{ steps.changelog.outputs.changelog }}
82
- draft: false
83
- prerelease: false
@@ -1,32 +0,0 @@
1
- name: CI
2
-
3
- on:
4
- pull_request:
5
- branches:
6
- - main
7
-
8
- jobs:
9
- build:
10
- runs-on: ubuntu-latest
11
-
12
- strategy:
13
- matrix:
14
- node-version: ['20.x', '22.x']
15
-
16
- steps:
17
- - name: Checkout code
18
- uses: actions/checkout@v3
19
-
20
- - name: Set up Node.js
21
- uses: actions/setup-node@v3
22
- with:
23
- node-version: ${{ matrix.node-version }}
24
-
25
- - name: Install dependencies
26
- run: yarn install
27
-
28
- - name: Run TypeScript checks
29
- run: yarn run check
30
-
31
- - name: Run tests
32
- run: yarn run test
@@ -1,34 +0,0 @@
1
- # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2
- # For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
3
-
4
- name: Node.js Package
5
-
6
- on:
7
- release:
8
- types: [created]
9
-
10
- jobs:
11
- build:
12
- runs-on: ubuntu-latest
13
- steps:
14
- - uses: actions/checkout@v4
15
- - uses: actions/setup-node@v4
16
- with:
17
- node-version: 20
18
- - run: yarn install
19
- - run: yarn test
20
-
21
- publish-npm:
22
- needs: build
23
- runs-on: ubuntu-latest
24
- steps:
25
- - uses: actions/checkout@v4
26
- - uses: actions/setup-node@v4
27
- with:
28
- node-version: 20
29
- registry-url: https://registry.npmjs.org/
30
- - run: yarn install
31
- - run: yarn build
32
- - run: npm publish
33
- env:
34
- NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
package/.gitignore DELETED
@@ -1,67 +0,0 @@
1
- # Dependencies
2
- node_modules/
3
- npm-debug.log
4
- yarn-error.log
5
- yarn-debug.log
6
- .pnp/
7
- .pnp.js
8
-
9
- # TypeScript
10
- *.tsbuildinfo
11
-
12
- # Compiled output
13
- dist/
14
- build/
15
- out/
16
-
17
- # IDEs and editors
18
- .vscode/
19
- .idea/
20
- *.swp
21
- *.swo
22
- *.sublime-workspace
23
-
24
- # Operating System Files
25
- .DS_Store
26
- Thumbs.db
27
-
28
- # Environment variables
29
- .env
30
- .env.local
31
- .env.development.local
32
- .env.test.local
33
- .env.production.local
34
-
35
- # Debug logs
36
- logs
37
- *.log
38
- npm-debug.log*
39
- yarn-debug.log*
40
- yarn-error.log*
41
-
42
- # Coverage directory used by tools like istanbul
43
- coverage/
44
-
45
- # Temporary folders
46
- tmp/
47
- temp/
48
-
49
- # Optional npm cache directory
50
- .npm
51
-
52
- # Optional eslint cache
53
- .eslintcache
54
-
55
- # Optional REPL history
56
- .node_repl_history
57
-
58
- # Output of 'npm pack'
59
- *.tgz
60
-
61
- # Yarn Integrity file
62
- .yarn-integrity
63
-
64
- # Stores VSCode versions used for testing VSCode extensions
65
- .vscode-test
66
- .clovingprojects
67
- .yarn
@@ -1 +0,0 @@
1
- *
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env sh
2
- . "$(dirname "$0")/h"
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env sh
2
- . "$(dirname "$0")/h"
package/.husky/_/h DELETED
@@ -1,22 +0,0 @@
1
- #!/usr/bin/env sh
2
- [ "$HUSKY" = "2" ] && set -x
3
- n=$(basename "$0")
4
- s=$(dirname "$(dirname "$0")")/$n
5
-
6
- [ ! -f "$s" ] && exit 0
7
-
8
- if [ -f "$HOME/.huskyrc" ]; then
9
- echo "husky - '~/.huskyrc' is DEPRECATED, please move your code to ~/.config/husky/init.sh"
10
- fi
11
- i="${XDG_CONFIG_HOME:-$HOME/.config}/husky/init.sh"
12
- [ -f "$i" ] && . "$i"
13
-
14
- [ "${HUSKY-}" = "0" ] && exit 0
15
-
16
- export PATH="node_modules/.bin:$PATH"
17
- sh -e "$s" "$@"
18
- c=$?
19
-
20
- [ $c != 0 ] && echo "husky - $n script failed (code $c)"
21
- [ $c = 127 ] && echo "husky - command not found in PATH=$PATH"
22
- exit $c
package/.husky/_/husky.sh DELETED
@@ -1,9 +0,0 @@
1
- echo "husky - DEPRECATED
2
-
3
- Please remove the following two lines from $0:
4
-
5
- #!/usr/bin/env sh
6
- . \"\$(dirname -- \"\$0\")/_/husky.sh\"
7
-
8
- They WILL FAIL in v10.0.0
9
- "
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env sh
2
- . "$(dirname "$0")/h"
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env sh
2
- . "$(dirname "$0")/h"
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env sh
2
- . "$(dirname "$0")/h"
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env sh
2
- . "$(dirname "$0")/h"
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env sh
2
- . "$(dirname "$0")/h"
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env sh
2
- . "$(dirname "$0")/h"
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env sh
2
- . "$(dirname "$0")/h"
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env sh
2
- . "$(dirname "$0")/h"
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env sh
2
- . "$(dirname "$0")/h"
package/.husky/_/pre-push DELETED
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env sh
2
- . "$(dirname "$0")/h"
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env sh
2
- . "$(dirname "$0")/h"
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env sh
2
- . "$(dirname "$0")/h"
package/.husky/pre-commit DELETED
@@ -1 +0,0 @@
1
- npx lint-staged
package/.husky/pre-push DELETED
@@ -1 +0,0 @@
1
- npx lint-prepush
package/.prettierrc.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "semi": false,
3
- "trailingComma": "all",
4
- "singleQuote": true,
5
- "printWidth": 100,
6
- "tabWidth": 2
7
- }
package/.tool-versions DELETED
@@ -1,2 +0,0 @@
1
- yarn 1.22.22
2
- nodejs 20.16.0
package/SECURITY.md DELETED
@@ -1,15 +0,0 @@
1
- # Security Policy
2
-
3
- ## Data sensitivity
4
-
5
- The sensitive data that is currently handled by the Cloving CLI is:
6
-
7
- - Various AI API keys, which are stored in the cloving configuration within the **user home directory** (`~/.clovingconfig`).
8
-
9
- ## Reporting a Vulnerability
10
-
11
- Report vulnerabilities to security [at] cloving.ai
12
-
13
- They will be handled ASAP.
14
- If the vulnerability is accepted, a mitigation will be implemented and a proper disclosure will be released.
15
- The triage and mitigation process will depend on the potential severity and impact of the vulnerability.
package/cloving.json DELETED
@@ -1,67 +0,0 @@
1
- {
2
- "languages": [
3
- {
4
- "name": "TypeScript",
5
- "version": "^5.5.4",
6
- "primary": true,
7
- "directory": "src",
8
- "extension": ".ts"
9
- },
10
- {
11
- "name": "JavaScript",
12
- "version": "ES2020",
13
- "directory": "src",
14
- "extension": ".js"
15
- }
16
- ],
17
- "frameworks": [
18
- {
19
- "name": "Node.js",
20
- "type": "Runtime environment",
21
- "primary": true,
22
- "directory": "src",
23
- "extension": ".ts"
24
- },
25
- {
26
- "name": "Express",
27
- "type": "Web framework",
28
- "version": "^4.19.2",
29
- "directory": "src",
30
- "extension": ".ts"
31
- }
32
- ],
33
- "testingFrameworks": [
34
- {
35
- "name": "Jest",
36
- "type": "Testing framework",
37
- "version": "^29.7.0",
38
- "directory": "tests"
39
- }
40
- ],
41
- "buildTools": [
42
- {
43
- "name": "TypeScript Compiler (tsc)",
44
- "type": "Transpiler",
45
- "version": "^5.5.4"
46
- },
47
- {
48
- "name": "Vite",
49
- "type": "Build tool",
50
- "version": "^5.4.0"
51
- }
52
- ],
53
- "packageManager": "Yarn",
54
- "linters": [
55
- {
56
- "name": "ESLint",
57
- "version": "^8.57.0",
58
- "type": "Linter"
59
- },
60
- {
61
- "name": "Prettier",
62
- "version": "^3.2.5",
63
- "type": "Code formatter"
64
- }
65
- ],
66
- "projectType": "Command-line tool"
67
- }
package/jest.config.js DELETED
@@ -1,11 +0,0 @@
1
- /** @type {import('ts-jest').JestConfigWithTsJest} */
2
- module.exports = {
3
- preset: 'ts-jest',
4
- testEnvironment: 'node',
5
- testMatch: ['**/tests/**/*.test.ts'],
6
- moduleFileExtensions: ['ts', 'js'],
7
- transform: {
8
- '^.+\\.ts$': 'ts-jest',
9
- },
10
- }
11
-
@@ -1,83 +0,0 @@
1
- import { Adapter } from '.'
2
- import type { GPTRequest, OpenAIStreamChunk } from '../../utils/types'
3
-
4
- export class AzureOpenAIAdapter implements Adapter {
5
- private model: string
6
- private endpoint: string
7
-
8
- static supportedModels: string[] = [
9
- 'azureopenai:gpt:4o-2024-08-06',
10
- 'azureopenai:gpt:4o',
11
- 'azureopenai:gpt:4o-mini',
12
- 'azureopenai:gpt:4-turbo',
13
- 'azureopenai:gpt:3.5-turbo',
14
- // Add more supported models as needed
15
- ]
16
-
17
- static listSupportedModels(): void {
18
- AzureOpenAIAdapter.supportedModels.forEach((model) => {
19
- console.log(model)
20
- })
21
- }
22
-
23
- constructor(model: string, endpoint: string) {
24
- this.model = model
25
- this.endpoint = endpoint
26
- }
27
-
28
- getEndpoint(): string {
29
- return this.endpoint
30
- }
31
-
32
- getHeaders(apiKey: string): Record<string, string> {
33
- return {
34
- Authorization: `Bearer ${apiKey}`,
35
- 'Content-Type': 'application/json',
36
- }
37
- }
38
-
39
- getPayload(request: GPTRequest, stream: boolean = false): Record<string, any> {
40
- return {
41
- model: this.model.replace('azureopenai:', '').replace(':', '-'),
42
- messages:
43
- request.messages && request.messages.length > 0
44
- ? request.messages
45
- : [{ role: 'user', content: request.prompt }],
46
- max_tokens: request.maxTokens,
47
- temperature: request.temperature || 0.2,
48
- stream,
49
- }
50
- }
51
-
52
- extractResponse(data: any): string {
53
- return data.choices[0].message.content
54
- }
55
-
56
- convertStream(data: string): OpenAIStreamChunk | null {
57
- let beginningChar = 0
58
- let lastChar = 0
59
-
60
- while (lastChar < data.length) {
61
- try {
62
- let remainingString = data.slice(beginningChar, lastChar)
63
-
64
- const firstBraceIndex = remainingString.indexOf('{')
65
- if (firstBraceIndex > -1) {
66
- remainingString = remainingString.slice(firstBraceIndex)
67
- }
68
-
69
- const parsedObject = JSON.parse(remainingString)
70
- const output = parsedObject?.choices[0]?.delta?.content || ''
71
-
72
- return {
73
- output,
74
- lastChar,
75
- }
76
- } catch (error) {
77
- lastChar += 1
78
- }
79
- }
80
-
81
- return null
82
- }
83
- }