Skip to content

Commit 22da4e3

Browse files
Moloejoegitbook-bot
authored andcommitted
GITBOOK-21: JavaScript first
1 parent e16c8a0 commit 22da4e3

File tree

1 file changed

+44
-44
lines changed

1 file changed

+44
-44
lines changed

pgml-cms/blog/introducing-the-openai-switch-kit-move-from-closed-to-open-source-ai-in-minutes.md

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,27 @@ We think so. Open-source models have made remarkable strides, not only catching
3737
The Switch Kit is an open-source AI SDK that provides a drop in replacement for OpenAI’s chat completion endpoint.
3838

3939
{% tabs %}
40+
{% tab title="JavaScript" %}
41+
```javascript
42+
const pgml = require("pgml");
43+
const client = pgml.newOpenSourceAI();
44+
const results = client.chat_completions_create(
45+
"HuggingFaceH4/zephyr-7b-beta",
46+
[
47+
{
48+
role: "system",
49+
content: "You are a friendly chatbot who always responds in the style of a pirate",
50+
},
51+
{
52+
role: "user",
53+
content: "How many helicopters can a human eat in one sitting?",
54+
},
55+
],
56+
);
57+
console.log(results);
58+
```
59+
{% endtab %}
60+
4061
{% tab title="Python" %}
4162
```python
4263
import pgml
@@ -58,27 +79,6 @@ results = client.chat_completions_create(
5879
print(results)
5980
```
6081
{% endtab %}
61-
62-
{% tab title="JavaScript" %}
63-
```javascript
64-
const pgml = require("pgml");
65-
const client = pgml.newOpenSourceAI();
66-
const results = client.chat_completions_create(
67-
"HuggingFaceH4/zephyr-7b-beta",
68-
[
69-
{
70-
role: "system",
71-
content: "You are a friendly chatbot who always responds in the style of a pirate",
72-
},
73-
{
74-
role: "user",
75-
content: "How many helicopters can a human eat in one sitting?",
76-
},
77-
],
78-
);
79-
console.log(results);
80-
```
81-
{% endtab %}
8282
{% endtabs %}
8383

8484
```json
@@ -120,29 +120,6 @@ The best part of using open-source AI is the flexibility with models. Unlike Ope
120120
Here is an example of streaming with the popular Mythalion model, an uncensored MythoMax variant designed for chatting.
121121

122122
{% tabs %}
123-
{% tab title="Python" %}
124-
```python
125-
import pgml
126-
client = pgml.OpenSourceAI()
127-
results = client.chat_completions_create_stream(
128-
"PygmalionAI/mythalion-13b",
129-
[
130-
{
131-
"role": "system",
132-
"content": "You are a friendly chatbot who always responds in the style of a pirate",
133-
},
134-
{
135-
"role": "user",
136-
"content": "How many helicopters can a human eat in one sitting?",
137-
},
138-
],
139-
temperature=0.85,
140-
)
141-
for c in results:
142-
print(c)
143-
```
144-
{% endtab %}
145-
146123
{% tab title="JavaScript" %}
147124
```javascript
148125
const pgml = require("pgml");
@@ -167,6 +144,29 @@ while (!result.done) {
167144
}
168145
```
169146
{% endtab %}
147+
148+
{% tab title="Python" %}
149+
```python
150+
import pgml
151+
client = pgml.OpenSourceAI()
152+
results = client.chat_completions_create_stream(
153+
"PygmalionAI/mythalion-13b",
154+
[
155+
{
156+
"role": "system",
157+
"content": "You are a friendly chatbot who always responds in the style of a pirate",
158+
},
159+
{
160+
"role": "user",
161+
"content": "How many helicopters can a human eat in one sitting?",
162+
},
163+
],
164+
temperature=0.85,
165+
)
166+
for c in results:
167+
print(c)
168+
```
169+
{% endtab %}
170170
{% endtabs %}
171171

172172
```json

0 commit comments

Comments
 (0)