Skip to content

Commit

Permalink
feat(interface/chat_functions): use annotations for simpler drivers
Browse files Browse the repository at this point in the history
  • Loading branch information
stakach committed Oct 12, 2023
1 parent ad64b45 commit 754fbf4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: placeos-driver
version: 6.9.5
version: 6.9.6
crystal: ">= 1.0.0"

dependencies:
Expand Down
5 changes: 5 additions & 0 deletions src/placeos-driver/driver-specs/mock_driver.cr
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@ abstract class DriverSpecs::MockDriver
@@functions : String?
@@interface : String?

class_getter driver_interface : String do
functions
@@interface.as(String)
end

def self.functions
functions = @@interface
return {functions, @@functions.not_nil!} if functions
Expand Down
24 changes: 21 additions & 3 deletions src/placeos-driver/interface/chat_functions.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,30 @@ require "json"
abstract class PlaceOS::Driver
# provides a discoverable interface for LLMs
module Interface::ChatFunctions
annotation Description
end

macro build_function_descriptions
def function_descriptions
{
{% for method in @type.methods %}
{% if method.annotation(Description) %}
{{method.name}}: {{method.annotation(Description)[0]}},
{% end %}
{% end %}
}
end
end

macro included
macro finished
build_function_descriptions
end
end

# overall description of what this driver implements
abstract def capabilities : String

# function name => function description
abstract def function_descriptions : Hash(String, String)

# returns function name => [function description, {param name => JSON Schema}]
def function_schemas : Hash(String, Tuple(String, Hash(String, JSON::Any)))
# function name => {param name => JSON Schema}
Expand Down

0 comments on commit 754fbf4

Please sign in to comment.