Skip to content

Commit

Permalink
[UI] Model page code snippets fixes and improvements #2024 (#2026)
Browse files Browse the repository at this point in the history
  • Loading branch information
olgenn authored Nov 21, 2024
1 parent 47a3d03 commit 69eb0cf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
2 changes: 2 additions & 0 deletions frontend/src/libs/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export const getStatusIconType = (status: IRun['status']): StatusIndicatorProps[
};

export const getExtendedModelFromRun = (run: IRun): IModelExtended | null => {
if (!run?.service?.model) return null;

return {
...(run.service?.model ?? {}),
project_name: run.project_name,
Expand Down
30 changes: 17 additions & 13 deletions frontend/src/pages/Models/Details/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,36 @@ import { IModelExtended } from '../List/types';
export const getPythonModelCode = ({ model, token }: { model?: IModelExtended | null; token?: string }) => {
return `from openai import OpenAI
client = OpenAI(
api_key="${token}"
api_key="${token}",
base_url="${getModelGateway(model?.base_url ?? '')}"
)
response = client.chat.completions.create(
model="${model?.name ?? ''}",
messages=[],
stream=True,
max_tokens=512,
response_format={
"type": "text"
}
model="${model?.name ?? ''}",
messages=[
{
"role": "user",
"content": "Hello world",
},
],
stream=True,
max_tokens=512,
)`;
};

export const getCurlModelCode = ({ model, token }: { model?: IModelExtended | null; token?: string }) => {
return `curl ${getModelGateway(model?.base_url ?? '')} \\
return `curl ${getModelGateway(model?.base_url ?? '') + 'chat/completions'} \\
-H "Content-Type: application/json" \\
-H "Authorization: Bearer ${token}" \\
-d '{
"model": "${model?.name ?? ''}",
"messages": [],
"messages": [
{
"role": "user",
"content": "Hello world"
}
],
"stream": true,
"max_tokens": 512,
"response_format": {
"type": "text"
}
}'`;
};
2 changes: 2 additions & 0 deletions frontend/src/pages/Models/Details/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ export const ModelDetails: React.FC = () => {
}
};

console.log({ modelData });

return (
<ContentLayout
header={
Expand Down

0 comments on commit 69eb0cf

Please sign in to comment.