Skip to content

Commit

Permalink
fix: converts answer body to url encoded
Browse files Browse the repository at this point in the history
  • Loading branch information
micheleriva committed Apr 30, 2024
1 parent 66186f5 commit 0d7d535
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
17 changes: 9 additions & 8 deletions src/answerSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,22 @@ export class AnswerSession {

private async *fetchAnswer(query: string, context: Context): AsyncGenerator<string> {
this.abortController = new AbortController()

const { signal } = this.abortController
const contextDocuments = context.map((hit) => hit.document)
const requestBody = new URLSearchParams()

const requestBody = {
type: this.inferenceType,
messages: this.messages,
context,
query
}
requestBody.append('type', this.inferenceType)
requestBody.append('messages', JSON.stringify(this.messages))
requestBody.append('context', JSON.stringify(contextDocuments))
requestBody.append('query', query)

const response = await fetch(this.endpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
'Content-Type': 'application/x-www-form-urlencoded'
},
body: JSON.stringify(requestBody),
body: requestBody,
signal
})

Expand Down
1 change: 0 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ export class OramaClient {
.map(([key, value]) => `${key}=${encodeURIComponent(JSON.stringify(value))}`)
.join('&')
}

const res: Response = await fetch(`${this.endpoint}/${path}?api-key=${this.api_key}`, requestOptions)

if (!res.ok) {
Expand Down
16 changes: 8 additions & 8 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export const MICROSECONDS_BASE = 1_000_000;
export const MICROSECONDS_BASE = 1_000_000

export const DEFAULT_TELEMETRY_FLUSH_INTERVAL = 5000;
export const DEFAULT_TELEMETRY_FLUSH_INTERVAL = 5000

export const DEFAULT_TELEMETRY_FLUSH_SIZE = 25;
export const DEFAULT_TELEMETRY_FLUSH_SIZE = 25

export const ORAMA_PROXY_ENDPOINT = "https://secure-proxy.orama.run";
export const ORAMA_PROXY_INIT_ENDPOINT = "/init";
export const ORAMA_PROXY_CHAT_ENDPOINT = "/chat";
export const ORAMA_PROXY_SUMMARY_ENDPOINT = "/summary";
export const ORAMA_PROXY_EMBEDDINGS_ENDPOINT = "/query";
export const ORAMA_PROXY_ENDPOINT = 'https://secure-proxy.orama.run'
export const ORAMA_PROXY_INIT_ENDPOINT = '/init'
export const ORAMA_PROXY_CHAT_ENDPOINT = '/chat'
export const ORAMA_PROXY_SUMMARY_ENDPOINT = '/summary'
export const ORAMA_PROXY_EMBEDDINGS_ENDPOINT = '/query'

0 comments on commit 0d7d535

Please sign in to comment.