Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support vision models and function calling #8

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/jupyter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Jupyter Notebooks

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
check-notebooks:
name: Check Jupyter notebooks
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: Install pre-commit
run: pip install pre-commit

- name: Run pre-commit
run: pre-commit run nbstripout --all-files
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,8 @@ iOSInjectionProject/
/Packages
.netrc
.idea
.swiftpm
.swiftpm

# Specific to this package

*.code-workspace
6 changes: 5 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
repos:
- repo: https://github.com/slessans/pre-commit-swift-format
rev: ""
rev: "fd627de92bdf84a75c924ed95691336d14e94cf1"
hooks:
- id: swift-format
args: ["--configuration", ".swift-format"]
- repo: https://github.com/kynan/nbstripout
rev: 0.8.1
hooks:
- id: nbstripout
5 changes: 4 additions & 1 deletion .swift-format
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@
"respectsExistingLineBreaks": true,
"lineBreakBeforeEachArgument": true,
"multiElementCollectionTrailingCommas": true,
"spacesAroundRangeFormationOperators": true
"spacesAroundRangeFormationOperators": true,
"rules": {
"AlwaysUseLowerCamelCase": false
}
}
14 changes: 14 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"pins" : [
{
"identity" : "swift-collections",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections.git",
"state" : {
"revision" : "671108c96644956dddcd89dd59c203dcdb36cec7",
"version" : "1.1.4"
}
}
],
"version" : 2
}
10 changes: 9 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,25 @@ let package = Package(
targets: ["Jinja"]
)
],
dependencies: [
.package(url: "https://github.com/apple/swift-collections.git", from: "1.1.4")
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.target(
name: "Jinja",
dependencies: [
.product(name: "OrderedCollections", package: "swift-collections")
],
path: "Sources",
swiftSettings: [.enableUpcomingFeature("BareSlashRegexLiterals")]
),
.testTarget(
name: "JinjaTests",
dependencies: ["Jinja"],
dependencies: [
"Jinja"
],
path: "Tests",
swiftSettings: [.enableUpcomingFeature("BareSlashRegexLiterals")]
),
Expand Down
146 changes: 146 additions & 0 deletions Python/test-chat-template.ipynb
DePasqualeOrg marked this conversation as resolved.
Show resolved Hide resolved

Large diffs are not rendered by default.

37 changes: 31 additions & 6 deletions Sources/Ast.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import Foundation
import OrderedCollections

protocol Statement {}

Expand Down Expand Up @@ -41,15 +42,15 @@ struct TupleLiteral: Literal {
}

struct ObjectLiteral: Literal {
var value: [(Expression, Expression)]
var value: OrderedDictionary<String, Expression>
}

struct Set: Statement {
var assignee: Expression
var value: Expression
}

struct If: Statement {
struct If: Statement, Expression {
var test: Expression
var body: [Statement]
var alternate: [Statement]
Expand All @@ -59,14 +60,14 @@ struct Identifier: Expression {
var value: String
}

protocol Loopvar {}
extension Identifier: Loopvar {}
extension TupleLiteral: Loopvar {}
typealias Loopvar = Expression

struct For: Statement {
var loopvar: Loopvar
var iterable: Expression
var body: [Statement]
var defaultBlock: [Statement]
var ifCondition: Expression?
johnmai-dev marked this conversation as resolved.
Show resolved Hide resolved
}

struct MemberExpression: Expression {
Expand All @@ -92,7 +93,11 @@ extension CallExpression: Filter {}

struct FilterExpression: Expression {
var operand: Expression
var filter: Filter
var filter: Identifier
var args: [Expression]
var kwargs: [KeywordArgumentExpression]
var dyn_args: Expression?
var dyn_kwargs: Expression?
}

struct TestExpression: Expression {
Expand Down Expand Up @@ -124,3 +129,23 @@ struct KeywordArgumentExpression: Expression {
struct NullLiteral: Literal {
var value: Any? = nil
}

struct SelectExpression: Expression {
var iterable: Expression
var test: Expression
}

struct Macro: Statement {
var name: Identifier
var args: [Expression]
var body: [Statement]
}

struct KeywordArgumentsValue: RuntimeValue {
var value: [String: any RuntimeValue]
var builtins: [String: any RuntimeValue] = [:]

func bool() -> Bool {
!value.isEmpty
}
}
Loading
Loading