-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from leftmove/allow-interruptions
Allow interruptions
- Loading branch information
Showing
6 changed files
with
193 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[project] | ||
name = "cria" | ||
version = "1.6.2" | ||
version = "1.6.5" | ||
authors = [{ name = "leftmove", email = "[email protected]" }] | ||
description = "Run AI locally with as little friction as possible" | ||
readme = "README.md" | ||
|
@@ -17,7 +17,7 @@ Issues = "https://github.com/leftmove/cria/issues" | |
|
||
[tool.poetry] | ||
name = "cria" | ||
version = "1.6.2" | ||
version = "1.6.5" | ||
description = "Run AI locally with as little friction as possible." | ||
authors = ["leftmove"] | ||
license = "MIT" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from src import cria | ||
|
||
ai = cria.Model(allow_interruption=False) | ||
|
||
response = "" | ||
max_token_length = 5 | ||
|
||
prompt = "Who is the CEO of OpenAI?" | ||
for i, chunk in enumerate(ai.chat(prompt)): | ||
if i >= max_token_length: | ||
ai.stop() | ||
break | ||
|
||
print(chunk, end="") # The CEO of OpenAI is | ||
|
||
prompt = "Tell me more about him." | ||
for chunk in ai.chat(prompt): | ||
print( | ||
chunk, end="" | ||
) # I apologize, but I don't have any information about "him" because the conversation just started... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import unittest | ||
|
||
from src import cria | ||
|
||
ai = cria.Cria() | ||
interruption_length = 5 | ||
|
||
prompt = "Who is the CEO of OpenAI?" | ||
response = "" | ||
chunks = [] | ||
|
||
for i, chunk in enumerate(ai.chat(prompt)): | ||
chunks += chunk | ||
response += chunk | ||
print(chunk, end="") | ||
|
||
if i >= interruption_length: | ||
ai.stop() | ||
|
||
|
||
class TestChat(unittest.TestCase): | ||
def test_response(self): | ||
self.assertIsNot(response, "") | ||
|
||
def test_chunks(self): | ||
self.assertIsNot(chunks, []) | ||
|
||
def test_interruption_length(self): | ||
self.assertIsNot(len(ai.messages[-1]["content"]), 0) | ||
|
||
def test_response_length(self): | ||
self.assertIs(i, interruption_length) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import unittest | ||
|
||
from src import cria | ||
|
||
ai = cria.Cria() | ||
interruption_length = 5 | ||
|
||
prompt = "Who is the CEO of OpenAI?" | ||
response = "" | ||
chunks = [] | ||
|
||
for i, chunk in enumerate(ai.chat(prompt)): | ||
chunks += chunk | ||
response += chunk | ||
print(chunk, end="") | ||
|
||
if i >= interruption_length: | ||
ai.stop() | ||
|
||
|
||
class TestChat(unittest.TestCase): | ||
def test_response(self): | ||
self.assertIsNot(response, "") | ||
|
||
def test_chunks(self): | ||
self.assertIsNot(chunks, []) | ||
|
||
def test_interruption_length(self): | ||
self.assertIsNot(len(ai.messages[-1]["content"]), 0) | ||
|
||
def test_response_length(self): | ||
self.assertIs(i, interruption_length) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |