Skip to content

Commit e468d92

Browse files
committed
chore(openai-compatibility): remove unnecessary copy
1 parent 93f4d0f commit e468d92

File tree

1 file changed

+1
-108
lines changed

1 file changed

+1
-108
lines changed

fern/chat/openai-compatibility.mdx

Lines changed: 1 addition & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ We'll migrate "TechFlow's" existing OpenAI-powered customer support chat to use
391391
if (done) break;
392392

393393
const chunk = decoder.decode(value);
394-
// Process SSE events here
394+
// Process SSE events here...
395395
console.log(chunk);
396396
}
397397
}
@@ -413,7 +413,6 @@ We'll migrate "TechFlow's" existing OpenAI-powered customer support chat to use
413413
const app = express();
414414
app.use(express.json());
415415

416-
// Basic OpenAI-compatible chat endpoint
417416
app.post('/v1/chat/completions', async (req, res) => {
418417
const { messages, model, stream = false, assistant_id } = req.body;
419418

@@ -472,112 +471,6 @@ We'll migrate "TechFlow's" existing OpenAI-powered customer support chat to use
472471

473472
---
474473

475-
## 5. Test Your Migration
476-
477-
<Steps>
478-
<Step title="Test with existing OpenAI clients">
479-
Use your production server with standard OpenAI clients:
480-
481-
```bash title="Test with curl (OpenAI format)"
482-
curl -X POST http://localhost:3000/v1/chat/completions \
483-
-H "Content-Type: application/json" \
484-
-d '{
485-
"model": "gpt-4o",
486-
"messages": [
487-
{"role": "user", "content": "Hello, I need technical support"}
488-
],
489-
"assistant_id": "your-assistant-id",
490-
"stream": false
491-
}'
492-
```
493-
</Step>
494-
<Step title="Test streaming compatibility">
495-
Verify streaming works with OpenAI format:
496-
497-
```typescript title="test-streaming-compatibility.ts"
498-
import OpenAI from 'openai';
499-
500-
// Test with your local server
501-
const localOpenAI = new OpenAI({
502-
apiKey: 'api-key',
503-
baseURL: 'http://localhost:3000/v1'
504-
});
505-
506-
const stream = await localOpenAI.chat.completions.create({
507-
model: 'gpt-4o',
508-
messages: [
509-
{ role: 'user', content: 'Explain cloud computing in detail' }
510-
],
511-
stream: true,
512-
// @ts-ignore - Custom parameter for Vapi compatibility
513-
assistant_id: 'your-assistant-id'
514-
});
515-
516-
for await (const chunk of stream) {
517-
const content = chunk.choices[0]?.delta?.content || '';
518-
process.stdout.write(content);
519-
}
520-
```
521-
</Step>
522-
<Step title="Compare performance and responses">
523-
Run side-by-side tests to validate migration quality:
524-
525-
```typescript title="migration-validation.ts"
526-
import OpenAI from 'openai';
527-
528-
const openai = new OpenAI({
529-
apiKey: 'YOUR_VAPI_API_KEY',
530-
baseURL: 'https://api.vapi.ai/chat'
531-
});
532-
533-
async function compareResponses(prompt: string): Promise<void> {
534-
console.log('Testing prompt:', prompt);
535-
console.log('---');
536-
537-
// Test Vapi response
538-
const vapiResponse = await openai.responses.create({
539-
model: 'gpt-4o',
540-
input: prompt,
541-
assistantId: 'your-assistant-id',
542-
stream: false
543-
});
544-
545-
console.log('Vapi Response:');
546-
console.log(vapiResponse.output[0].content[0].text);
547-
console.log('---');
548-
549-
// You could also test with original OpenAI here for comparison
550-
// const openaiResponse = await originalOpenAI.chat.completions.create({...});
551-
}
552-
553-
// Test various scenarios
554-
await compareResponses("What are your customer support hours?");
555-
await compareResponses("I'm having trouble with API authentication");
556-
await compareResponses("Can you explain your pricing plans?");
557-
```
558-
</Step>
559-
</Steps>
560-
561-
## Key Differences from OpenAI
562-
563-
| Aspect | OpenAI | Vapi Compatible |
564-
|--------|--------|-----------------|
565-
| **Endpoint** | `/chat/completions` | `/chat/responses` |
566-
| **Messages** | `messages` array | `input` string + `previousChatId` |
567-
| **Assistant** | Model determines behavior | `assistantId` required |
568-
| **Context** | Full message history | Efficient context linking |
569-
| **Base URL** | `api.openai.com/v1` | `api.vapi.ai/chat` |
570-
571-
## Migration Checklist
572-
573-
- [ ] Updated API keys and base URLs
574-
- [ ] Changed `chat.completions.create` to `responses.create`
575-
- [ ] Added `assistantId` to all requests
576-
- [ ] Updated context management to use `previousChatId`
577-
- [ ] Tested both streaming and non-streaming modes
578-
- [ ] Validated response quality matches expectations
579-
- [ ] Updated error handling for Vapi-specific errors
580-
581474
## Next Steps
582475

583476
Enhance your migrated system:

0 commit comments

Comments
 (0)