Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow port to be null #371

Merged
merged 3 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@
},
"twinny.ollamaApiPort": {
"order": 15,
"type": "number",
"type": ["number", "null"],
"default": 11434,
"markdownDescription": "Sets the port number for the Ollama API. The default is `11434`, but you can change it if your Ollama instance uses a different port.",
"required": false
Expand Down
2 changes: 1 addition & 1 deletion src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export type Bracket = (typeof ALL_BRACKETS)[number]
export interface StreamRequestOptions {
hostname: string
path: string
port: string | number
port?: string | number
protocol: string
method: string
headers: Record<string, string>
Expand Down
4 changes: 2 additions & 2 deletions src/extension/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export async function streamResponse(request: StreamRequest) {
const { signal } = controller

try {
const url = `${options.protocol}://${options.hostname}:${options.port}${options.path}`
const url = `${options.protocol}://${options.hostname}${options.port ? `:${options.port}` : ""}${options.path}`
const fetchOptions = {
method: options.method,
headers: options.headers,
Expand Down Expand Up @@ -94,7 +94,7 @@ export async function fetchEmbedding(request: StreamRequest) {


try {
const url = `${options.protocol}://${options.hostname}:${options.port}${options.path}`
const url = `${options.protocol}://${options.hostname}${options.port ? `:${options.port}` : ""}${options.path}`
const fetchOptions = {
method: options.method,
headers: options.headers,
Expand Down
2 changes: 1 addition & 1 deletion src/extension/chat-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ export class ChatService {

const requestOptions: StreamRequestOptions = {
hostname: provider.apiHostname,
port: Number(provider.apiPort),
port: provider.apiPort ? Number(provider.apiPort) : undefined,
path: provider.apiPath,
protocol: provider.apiProtocol,
method: "POST",
Expand Down
2 changes: 1 addition & 1 deletion src/extension/conversation-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export class ConversationHistory {
private getRequestOptions(provider: TwinnyProvider) {
return {
hostname: provider.apiHostname,
port: Number(provider.apiPort),
port: provider.apiPort ? Number(provider.apiPort) : undefined,
path: provider.apiPath,
protocol: provider.apiProtocol,
method: "POST",
Expand Down
2 changes: 1 addition & 1 deletion src/extension/provider-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { apiProviders, ClientMessage, ServerMessage } from "../common/types"
export interface TwinnyProvider {
apiHostname: string
apiPath: string
apiPort: number
apiPort?: number
apiProtocol: string
id: string
label: string
Expand Down
2 changes: 1 addition & 1 deletion src/extension/providers/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export class CompletionProvider implements InlineCompletionItemProvider {

const options: StreamRequestOptions = {
hostname: provider.apiHostname,
port: Number(provider.apiPort),
port: provider.apiPort ? Number(provider.apiPort) : undefined,
path: provider.apiPath,
protocol: provider.apiProtocol,
method: "POST",
Expand Down
4 changes: 2 additions & 2 deletions src/extension/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -732,15 +732,15 @@ export function readGitIgnoreFile(): string[] | undefined {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const logStreamOptions = (opts: any) => {
const hostname = opts.options?.hostname ?? "unknown"
const port = opts.options?.port ?? "unknown"
const port = opts.options?.port ?? undefined
const body = opts.body ?? {}
const options = opts.options ?? {}

const totalCharacters = calculateTotalCharacters(body.messages)

const logMessage = `
***Twinny Stream Debug***
Streaming response from ${hostname}:${port}.
Streaming response from ${hostname}${port ? `:${port}` : ""}.
Request body:
${JSON.stringify(body, null, 2)}

Expand Down
5 changes: 2 additions & 3 deletions src/webview/providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -373,13 +373,12 @@ function ProviderForm({ onClose, provider }: ProviderFormProps) {

<div>
<div>
<label htmlFor="apiPort">Port*</label>
<label htmlFor="apiPort">Port</label>
</div>
<VSCodeTextField
required
onChange={handleChange}
name="apiPort"
value={formState.apiPort.toString()}
value={formState.apiPort ? formState.apiPort.toString() : ""}
placeholder='Enter a port e.g "11434"'
></VSCodeTextField>
</div>
Expand Down